Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

C++

C++ map insert

std::map<int,string> output;
output.insert(pair<int,string>(1,"hehehe"));
https://snipt.net/embed/6033040a2fa80a777ab2475084878b70/
https://snipt.net/raw/6033040a2fa80a777ab2475084878b70/
6033040a2fa80a777ab2475084878b70
cpp
C++
2
2016-12-03T11:39:50
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://snipt.net/embed/d44388a5089c6f6f4ef13ed0824992e3/
https://snipt.net/raw/d44388a5089c6f6f4ef13ed0824992e3/
d44388a5089c6f6f4ef13ed0824992e3
cpp
C++
7
2016-12-02T15:38:24
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
Copyrighted, illegal, or inappropriate content? Email [email protected].