snipt

Ctrl+h for KB shortcuts

C++

Convert LPCWSTR to char string in VC++

1
2
3
4
5
6
7
#include <ole2.h> 
#define BUFFER_SIZE 100

size_t   i;
LPCWSTR strLPCWSTR = L"sometext";
char *strChar = new char[BUFFER_SIZE];
wcstombs_s(&i, strChar, (size_t)BUFFER_SIZE, strLPCWSTR, (size_t)BUFFER_SIZE);
https://snippets.siftie.com/embed/9b150d11d50e3dcc44ce471eb8058378/
/raw/9b150d11d50e3dcc44ce471eb8058378/
9b150d11d50e3dcc44ce471eb8058378
cpp
C++
8
2019-03-24T05:20:29
True
False
False
/api/public/snipt/50878/
convert-lpcwstr-to-char-string-in-vc
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">#include</span> <span class="cpf">&lt;ole2.h&gt; </span><span class="cp"></span> </span><span id="L-2"><a name="L-2"></a><span class="cp">#define BUFFER_SIZE 100</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="kt">size_t</span> <span class="n">i</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="n">LPCWSTR</span> <span class="n">strLPCWSTR</span> <span class="o">=</span> <span class="s">L&quot;sometext&quot;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="kt">char</span> <span class="o">*</span><span class="n">strChar</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">BUFFER_SIZE</span><span class="p">];</span> </span><span id="L-7"><a name="L-7"></a><span class="n">wcstombs_s</span><span class="p">(</span><span class="o">&amp;</span><span class="n">i</span><span class="p">,</span> <span class="n">strChar</span><span class="p">,</span> <span class="p">(</span><span class="kt">size_t</span><span class="p">)</span><span class="n">BUFFER_SIZE</span><span class="p">,</span> <span class="n">strLPCWSTR</span><span class="p">,</span> <span class="p">(</span><span class="kt">size_t</span><span class="p">)</span><span class="n">BUFFER_SIZE</span><span class="p">);</span> </span></pre></div> </td></tr></table>
C++

C++

C++ map insert

std::map<int,string> output;
output.insert(pair<int,string>(1,"hehehe"));
https://snippets.siftie.com/embed/6033040a2fa80a777ab2475084878b70/
/raw/6033040a2fa80a777ab2475084878b70/
6033040a2fa80a777ab2475084878b70
cpp
C++
2
2019-03-24T05:18:34
True
False
False
Aug 22, 2012 at 03:21 AM
/api/public/snipt/46099/
c-map-insert
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">std</span><span class="o">::</span><span class="n">map</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span><span class="n">string</span><span class="o">&gt;</span> <span class="n">output</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">output</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">pair</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span><span class="n">string</span><span class="o">&gt;</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="s">&quot;hehehe&quot;</span><span class="p">));</span> </span></pre></div> </td></tr></table>
C++, map

C++

map: get value by key

1
2
3
4
5
6
7
map<int,Bar>::iterator it = m.find('2');
Bar b3;
if(it != m.end())
{
   //element found;
   b3 = it->second;
}
https://snippets.siftie.com/embed/d44388a5089c6f6f4ef13ed0824992e3/
/raw/d44388a5089c6f6f4ef13ed0824992e3/
d44388a5089c6f6f4ef13ed0824992e3
cpp
C++
7
2019-03-20T08:36:59
True
False
False
Aug 20, 2012 at 02:55 AM
/api/public/snipt/45976/
map-get-value-by-key
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">map</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span><span class="n">Bar</span><span class="o">&gt;::</span><span class="n">iterator</span> <span class="n">it</span> <span class="o">=</span> <span class="n">m</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="sc">&#39;2&#39;</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="n">Bar</span> <span class="n">b3</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span><span class="p">(</span><span class="n">it</span> <span class="o">!=</span> <span class="n">m</span><span class="p">.</span><span class="n">end</span><span class="p">())</span> </span><span id="L-4"><a name="L-4"></a><span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="c1">//element found;</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">b3</span> <span class="o">=</span> <span class="n">it</span><span class="o">-&gt;</span><span class="n">second</span><span class="p">;</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
C++, map