<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[einzelenes element aus std::map holen]]></title><description><![CDATA[<p>ich muss aus map nen bestimmten inhalt rausbekommen<br />
ich hab ne schleife dort wird eben alles durchgegangen<br />
und dann aht man eben immer zugriff auf einen (i-&gt;first)<br />
ich muss an einer stelle aber direkten zugriff auf das andere bekommen</p>
<p>hab es versucht mit<br />
std::cout&lt;&lt;r-&gt;params_[&quot;threatID&quot;]&lt;&lt;std::endl;</p>
<p>problem ich habe damit zwar direkten zugriff auf diese element<br />
ist es aber nicht vorhanden schmiert das programm ab</p>
<p>meine frage gibt es ne andere möglichkeit für nen direkten zugriff<br />
oder kann man das abändern so das das programm nicht mehr abstürzt</p>
<p>hatte zwar schon etwas über get gelesen finde aber nicht die angaben wie es funktioniert es soll ja wenn es das element nicht findet 0 zurück</p>
<pre><code class="language-cpp">for (std::map&lt;std::string, std::string&gt;::const_iterator i = r-&gt;params_.begin();
         i != r-&gt;params_.end();
         i++) {

       body += &quot;&lt;br&gt;&quot; + i-&gt;first + &quot; = &quot; + i-&gt;second;

       forumindex = 1;
       int j = 1;
       if(i-&gt;first == &quot;catID&quot;) 

 //  std::cout&lt;&lt;r-&gt;params_[&quot;threatID&quot;]&lt;&lt;std::endl; 

         {body   += ForumCatIndex(body, i-&gt;second);}
       if(i-&gt;first == &quot;threatID&quot;) 
         {body   += ForumThreat( body, i-&gt;second);}      

    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/117744/einzelenes-element-aus-std-map-holen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 04:31:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/117744.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Aug 2005 21:25:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to einzelenes element aus std::map holen on Wed, 10 Aug 2005 21:25:13 GMT]]></title><description><![CDATA[<p>ich muss aus map nen bestimmten inhalt rausbekommen<br />
ich hab ne schleife dort wird eben alles durchgegangen<br />
und dann aht man eben immer zugriff auf einen (i-&gt;first)<br />
ich muss an einer stelle aber direkten zugriff auf das andere bekommen</p>
<p>hab es versucht mit<br />
std::cout&lt;&lt;r-&gt;params_[&quot;threatID&quot;]&lt;&lt;std::endl;</p>
<p>problem ich habe damit zwar direkten zugriff auf diese element<br />
ist es aber nicht vorhanden schmiert das programm ab</p>
<p>meine frage gibt es ne andere möglichkeit für nen direkten zugriff<br />
oder kann man das abändern so das das programm nicht mehr abstürzt</p>
<p>hatte zwar schon etwas über get gelesen finde aber nicht die angaben wie es funktioniert es soll ja wenn es das element nicht findet 0 zurück</p>
<pre><code class="language-cpp">for (std::map&lt;std::string, std::string&gt;::const_iterator i = r-&gt;params_.begin();
         i != r-&gt;params_.end();
         i++) {

       body += &quot;&lt;br&gt;&quot; + i-&gt;first + &quot; = &quot; + i-&gt;second;

       forumindex = 1;
       int j = 1;
       if(i-&gt;first == &quot;catID&quot;) 

 //  std::cout&lt;&lt;r-&gt;params_[&quot;threatID&quot;]&lt;&lt;std::endl; 

         {body   += ForumCatIndex(body, i-&gt;second);}
       if(i-&gt;first == &quot;threatID&quot;) 
         {body   += ForumThreat( body, i-&gt;second);}      

    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/849757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849757</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Wed, 10 Aug 2005 21:25:13 GMT</pubDate></item><item><title><![CDATA[Reply to einzelenes element aus std::map holen on Thu, 11 Aug 2005 07:24:12 GMT]]></title><description><![CDATA[<p>Morgen,</p>
<p>du koenntest mit map::count erst einmal schauen, ob der Schluessel ueberhaupt verhanden ist, ist dem so, dann<br />
kannst du direkt drauf zugreifen:</p>
<pre><code class="language-cpp">if(mapVar.count(key))
     return mapVar[key];
</code></pre>
<p>oder mit map::find. Liefert dir map::end(), falls der Schluessel nicht gefunden wird:</p>
<pre><code class="language-cpp">map&lt;T&gt;::iterator it = mapVar.find(key);
if(it != mapVar.end())
   do_something(it);
</code></pre>
<p>Ich nehme mal an, dich stoert so ein bisschen die Ueberpruefungen, aber die kannst du leider nicht weg-<br />
bekommen, zumindest faellt mir grad nicht ein wie.</p>
<p>mfg<br />
v R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849865</guid><dc:creator><![CDATA[virtuell Realisticer]]></dc:creator><pubDate>Thu, 11 Aug 2005 07:24:12 GMT</pubDate></item><item><title><![CDATA[Reply to einzelenes element aus std::map holen on Thu, 11 Aug 2005 12:57:47 GMT]]></title><description><![CDATA[<p>die überprüfun stört micht nicht wirklich</p>
<p>weil ich nur die if bedingunegen brauche und zwar folgende 3 varianten:</p>
<p>catID und threatID nicht vorhanden dann ForumIndex( body);<br />
catID vorhanden threatID nicht vorhanden dann ForumCatIndex(body,catID);<br />
catID und threatID vorhanden dann ForumThreat( body,catID, threatID);</p>
<p>mehr brauch ich ja nicht</p>
<p>nun gibts aber noch 2 probleme<br />
zum ersten</p>
<pre><code class="language-cpp">if(mapVar.count(key))
     return mapVar[key];
</code></pre>
<p>wie kann ich dort prüfen ob es nicht existiert und dann ne funktion ausführen</p>
<p>oder ist das dasselbe wie</p>
<pre><code class="language-cpp">if(mapVar.count(key)==TRUE)
     return mapVar[key];
</code></pre>
<p>mein 2. problem wäre das die for schleife weg kann oder ?</p>
<p>muss dann dort was anderes hin (wegen iterator) oder ckann ich count auch ohne aufs map zugreifen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850127</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850127</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Thu, 11 Aug 2005 12:57:47 GMT</pubDate></item><item><title><![CDATA[Reply to einzelenes element aus std::map holen on Thu, 11 Aug 2005 13:21:28 GMT]]></title><description><![CDATA[<p>Skippy schrieb:</p>
<blockquote>
<p>die überprüfun stört micht nicht wirklich</p>
<p>weil ich nur die if bedingunegen brauche und zwar folgende 3 varianten:</p>
<p>catID und threatID nicht vorhanden dann ForumIndex( body);<br />
catID vorhanden threatID nicht vorhanden dann ForumCatIndex(body,catID);<br />
catID und threatID vorhanden dann ForumThreat( body,catID, threatID);</p>
<p>mehr brauch ich ja nicht</p>
<p>nun gibts aber noch 2 probleme<br />
zum ersten</p>
<pre><code class="language-cpp">if(mapVar.count(key))
     return mapVar[key];
</code></pre>
<p>wie kann ich dort prüfen ob es nicht existiert und dann ne funktion ausführen</p>
</blockquote>
<p>Nun, map&lt;T&gt;::count liefert dir die Anzahl vorkommen des Schluessels 'key'. Ist keiner Vorhanden,<br />
so liefert map&lt;T&gt;::count 0 und die Bedingung ist nicht erfuellt.</p>
<blockquote>
<p>oder ist das dasselbe wie</p>
<pre><code class="language-cpp">if(mapVar.count(key)==TRUE)
     return mapVar[key];
</code></pre>
</blockquote>
<p>Wie gesagt, ist der Schluessel in der map enthalten, liefert dir count, wie oft der Schluessel vorhanden<br />
ist. Ist er vorhanden, ist die Bedingung erfuellt.</p>
<blockquote>
<p>mein 2. problem wäre das die for schleife weg kann oder ?</p>
</blockquote>
<p>Wenn ich das richtig sehe, dann setzt du mit jeder Iteration einen Teil mehr einer HTML-Seite(?) zusammen?<br />
Wenn dem so ist, dann kannst du auf die Schleife selbstverstaendlich nicht verzichten, denn du musst die<br />
map ja nachwievor durchlaufen, um die Seite zusammenzufuegen.</p>
<p>Liege ich mit meiner Vermutung richtig?</p>
<blockquote>
<p>muss dann dort was anderes hin (wegen iterator) oder ckann ich count auch ohne aufs map zugreifen</p>
</blockquote>
<p>Was meinst du mit count ohne auf die map zuzugreifen?</p>
<p>mfg<br />
v R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850145</guid><dc:creator><![CDATA[virtuell Realisticer]]></dc:creator><pubDate>Thu, 11 Aug 2005 13:21:28 GMT</pubDate></item><item><title><![CDATA[Reply to einzelenes element aus std::map holen on Thu, 11 Aug 2005 13:38:23 GMT]]></title><description><![CDATA[<p>zufälligerweise hat mein sinn und verstandlos rumprogrammieren sogar mal funktioniert</p>
<p>kannst dir ja mal in aktion ansehen</p>
<p><a href="http://skippy.dyndns.ws:8080/Forum/" rel="nofollow">http://skippy.dyndns.ws:8080/Forum/</a></p>
<p>hier mal die funktion wie sie jetzt aussieht</p>
<pre><code class="language-cpp">else if (r-&gt;path_ == &quot;/Forum/&quot;) {
    bgcolor = &quot;#f2f2f2' link='#0033cc' alink='#0033cc' vlink='#800080&quot;;
    title   = &quot;SKIPPSerV - Test Forum&quot;;

       if(r-&gt;params_.count(&quot;catID&quot;)==FALSE &amp;&amp; r-&gt;params_.count(&quot;threatID&quot;)==FALSE) 
         {body   = ForumIndex( body);} 

       if(r-&gt;params_.count(&quot;catID&quot;)==TRUE &amp;&amp; r-&gt;params_.count(&quot;threatID&quot;)==FALSE) 
         {body   += ForumCatIndex(body, r-&gt;params_[&quot;catID&quot;]);}

       if(r-&gt;params_.count(&quot;catID&quot;)==TRUE &amp;&amp; r-&gt;params_.count(&quot;threatID&quot;)==TRUE) 
         {body   += ForumThreat( body, r-&gt;params_[&quot;threatID&quot;]);}      

  }
</code></pre>
<p>die seite selbst wird ja in der funktion selbst zusammengesetzt daher übergebe ich den string body in dem der inhalt der des body tags der html seite abgelegt wird.</p>
<p>hier mal als beispiel die funktion</p>
<pre><code class="language-cpp">std::string ForumIndex(std::string body)
{

	char * dat_ein;
	char * token;
	char sLine[256];
	char Trenner[] = &quot;|@|&quot;;

	dat_ein = &quot;forum/forumindex.txt&quot;;

	ifstream Datei(dat_ein);

body +=&quot;&lt;center&gt;&quot;;
body +=&quot;&lt;table border='0' width='760' cellpadding='0' cellspacing='0'&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot; &lt;td class='logo' id='head' align='left'&gt;&quot;;
body +=&quot;  &lt;h1&gt;&lt;a href='http://skippy.dyndns.ws' title='Skippy - sagt: das macht spaß'&gt;SKIPPSerV - Test Forum&lt;span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;&quot;;
body +=&quot; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td align='left'&gt;&quot;;
body +=&quot;&lt;div class='BigPhorumForumTitle'&gt;&lt;strong&gt;SKIPPSerV Beta version Forum&lt;/strong&gt;&lt;/div&gt;&quot;;
body +=&quot;&lt;br /&gt;&quot;;
body +=&quot;&lt;table width='100%' cellspacing='0' cellpadding='3' border='0'&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;  &lt;td width='60%' nowrap='nowrap'  bgcolor='#f2f2f2'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;&amp;nbsp;&lt;a href='index.php?f=0'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Forum List&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='post.php?f=6'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;New Topic&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='search.php?f=6'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Search&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='login.php?f=6'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Log In&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td align='right' width='40%'  bgcolor='#f2f2f2'&gt;&lt;div class=nav&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;&amp;nbsp;&lt;a href='list.php?f=6&amp;t=1117391812&amp;a=2'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Older Messages&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;/td&gt;&quot;;
body +=&quot;&lt;/tr&gt;&quot;;
body +=&quot;&lt;/table&gt;&quot;;

body +=&quot;&lt;table class='PhorumListTable' width='100%' cellspacing='0' cellpadding='0' border='0'&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader'  bgcolor='#31a2c6'&gt;&lt;FONT color='#FFFFFF'&gt;&amp;nbsp;Topics&lt;img src='images/trans.gif' border=0 width=1 height=24 align='absmiddle'&gt;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader'  bgcolor='#31a2c6' width='150' nowrap='nowrap'&gt;&lt;FONT color='#FFFFFF'&gt;Moderator&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader' align='center'  bgcolor='#31a2c6' width='80' nowrap='nowrap'&gt;&lt;FONT color='#FFFFFF'&gt;Replies&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader'  bgcolor='#31a2c6' width='120' nowrap='nowrap'&gt;&lt;FONT color='#FFFFFF'&gt;Last Post&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;&lt;/tr&gt;&quot;;

	if ( !Datei )
	{
		cout &lt;&lt; &quot;Kann Datei ( &quot; &lt;&lt; dat_ein &lt;&lt; &quot; ) nicht öffnen&quot; &lt;&lt; endl;
	}

	while(!Datei.eof())
	{
		Datei.getline(sLine, 256);
	//	cout &lt;&lt; &quot;Zeile :&quot; &lt;&lt; sLine &lt;&lt; endl;

		// Zeile auseinandernehmen.
		token = strtok(sLine, Trenner);

body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow'  bgcolor='#FFFFFF'&gt;&lt;FONT color='#303030'&gt;&amp;nbsp;&lt;img src='images/trans.gif' border=0 width=1 height=21 align='absmiddle'&gt;&amp;nbsp;&lt;a href='/Forum/?catID=&quot;;
body += token;//catID der url hinzufügen
body += &quot;'&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//Titel der Kategorie
body +=&quot;&lt;/a&gt;&amp;nbsp;&lt;/font&gt;&lt;font class='PhorumNewFlag'&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//erweiterte Nachricht z.b. Wichtig, Neu, usw
body +=&quot;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow' width='150'  bgcolor='#FFFFFF' nowrap='nowrap'&gt;&lt;FONT color='#303030'&gt;&lt;strong&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//Author
body += &quot;&lt;/strong&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow' align='center' width='80'  bgcolor='#FFFFFF' nowrap='nowrap'&gt;&lt;FONT color='#303030' size=-1&gt;not aviable&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow' width='120'  bgcolor='#FFFFFF' nowrap='nowrap'&gt;&lt;FONT color='#303030' size=-1&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//Datum
body +=&quot;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&quot;;
			token = strtok(NULL, Trenner);

		while( token != NULL )
		{
		//	cout &lt;&lt; &quot;Token = &quot; &lt;&lt; token &lt;&lt; endl; //für debugzwecke
			token = strtok(NULL, Trenner); 
		}
	}
	return body; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/850176</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850176</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Thu, 11 Aug 2005 13:38:23 GMT</pubDate></item><item><title><![CDATA[Reply to einzelenes element aus std::map holen on Fri, 12 Aug 2005 09:13:21 GMT]]></title><description><![CDATA[<p>Hi, noch eine Ergänzung.<br />
Da die count-Methode mehrfach benutzt wird, solltest du sie nur einmal aufrufen, also z.B.</p>
<pre><code class="language-cpp">bool bCatId = (r-&gt;params_.count(&quot;catID&quot;) &gt; 0);
bool bThreadId = (r-&gt;params_.count(&quot;threatID&quot;) &gt; 0);

if(!bCatId &amp;&amp; !bThreadId) 
{
  body   = ForumIndex( body);
} 
else if(bCatId &amp;&amp; !bThreadId)
{
   body = ...;
}
else if(bCatId &amp;&amp; bThreadId)
{
   body = ...;
}
</code></pre>
<p>Außerdem liefert count einen int zurück, keinen BOOL, also teste auf &gt;0 bzw ==0.</p>
<p>Also kürzer und schneller...</p>
<p>P.S. Wenn du mehr Webseiten erzeugen willst, solltest du dich mal nach CGI-Programmierung erkundigen, dafür gibt es schon einfache, freie Klassen (z.B. uncgi, cgicc ...).</p>
<p>Zu empfehlen ist cgicc, aktuelle Version 3.2.1.</p>
<p>Außerdem solltest du evtl. Stylesheets verwenden, dann kannst du die Formatierungen, wie z.B. Farbe, Font etc. besser steuern, anstatt es für jeden HTML-Befehl('Tag') einzeln setzen zu müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/850632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/850632</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Fri, 12 Aug 2005 09:13:21 GMT</pubDate></item></channel></rss>