<?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[Strings]]></title><description><![CDATA[<p>Hallo,<br />
ich habe einen String und möchte dann einzelne Zeichen in ihm speichern,<br />
ungefähr so:</p>
<pre><code class="language-cpp">string str;
char c;

// bla

str += c;
</code></pre>
<p>Jetzt bricht das Programm aber immer ab, weil es einen Überlauf gibt. Muss ich<br />
die Größe des Strings am Anfang festlegen? Wird das nicht automatisch gemacht?</p>
<p>Vielen Dank!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/201909/strings</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 06:54:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201909.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 05 Jan 2008 15:39:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 15:39:20 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe einen String und möchte dann einzelne Zeichen in ihm speichern,<br />
ungefähr so:</p>
<pre><code class="language-cpp">string str;
char c;

// bla

str += c;
</code></pre>
<p>Jetzt bricht das Programm aber immer ab, weil es einen Überlauf gibt. Muss ich<br />
die Größe des Strings am Anfang festlegen? Wird das nicht automatisch gemacht?</p>
<p>Vielen Dank!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431192</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sat, 05 Jan 2008 15:39:20 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 15:44:01 GMT]]></title><description><![CDATA[<p>+= sollte sich eigentlich darum kümmern, dass immer genug speicher zur verfügung steht. der fehler liegt woanders. (vorausgesetzt, wir sprechen über std::strings)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431196</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Sat, 05 Jan 2008 15:44:01 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 15:49:30 GMT]]></title><description><![CDATA[<p>Soll ich, bevor ich += das erste mal verwende, davor noch str.clear(); schreiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431199</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431199</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sat, 05 Jan 2008 15:49:30 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 15:51:08 GMT]]></title><description><![CDATA[<p>Nein, du musst str vorher nur mit irgendwelchem Wert initialisieren, da der Inhalt ohne expliziter Wertzuweisung undefiniert ist. Mach's so:</p>
<pre><code class="language-cpp">string str = &quot;&quot;;
char c;

// bla
str += c;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1431200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431200</guid><dc:creator><![CDATA[mikey]]></dc:creator><pubDate>Sat, 05 Jan 2008 15:51:08 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 15:54:11 GMT]]></title><description><![CDATA[<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431201</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sat, 05 Jan 2008 15:54:11 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 16:09:16 GMT]]></title><description><![CDATA[<p>mikey schrieb:</p>
<blockquote>
<p>Nein, du musst str vorher nur mit irgendwelchem Wert initialisieren, da der Inhalt ohne expliziter Wertzuweisung undefiniert ist.</p>
</blockquote>
<p>nö, der standardkonstruktor erstellt einfach einen leeren string.</p>
<p>btw. solltest du sowieso nicht operator+= sondern push_back verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431221</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Sat, 05 Jan 2008 16:09:16 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 16:15:49 GMT]]></title><description><![CDATA[<p>queer_boy schrieb:</p>
<blockquote>
<p>btw. solltest du sowieso nicht operator+= sondern push_back verwenden.</p>
</blockquote>
<p>warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431230</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 05 Jan 2008 16:15:49 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 17:52:17 GMT]]></title><description><![CDATA[<p>push_back? Wenn dann wohl eher append. Aber += ist gleich append.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431300</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Sat, 05 Jan 2008 17:52:17 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 18:32:29 GMT]]></title><description><![CDATA[<p>Hmm nein? Warum nicht push_back? <a href="http://www.cplusplus.com/reference/string/string/push_back.html" rel="nofollow">http://www.cplusplus.com/reference/string/string/push_back.html</a> ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431340</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431340</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 05 Jan 2008 18:32:29 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 18:43:27 GMT]]></title><description><![CDATA[<p>Nun push_back erinnert eher mehr Listen. Nicht so sehr der Grund. Aus ein Charliteral kann schnell mal ein ein CharArray-Literal werden, dann muss du eh ein append oder += verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431352</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sat, 05 Jan 2008 18:43:27 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sat, 05 Jan 2008 19:32:40 GMT]]></title><description><![CDATA[<p>Hmm weil std::string auch als ein Container (nur halt mit Inhalt char-Array) angesehen werden kann, ist push_back vorhanden.(denke ich mal <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ). Nach der Referenz sollte die Funktion bei einzellnen chars aber identisch sein. Du hast recht, wenn du einen String anhängen willst, kannst du das nicht mit push_back, aber das ist auch bei anderen container-typen so: push_back fügt ein Item und keine Sequenz von Items ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431386</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 05 Jan 2008 19:32:40 GMT</pubDate></item><item><title><![CDATA[Reply to Strings on Sun, 06 Jan 2008 01:28:41 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>queer_boy schrieb:</p>
<blockquote>
<p>btw. solltest du sowieso nicht operator+= sondern push_back verwenden.</p>
</blockquote>
<p>warum?</p>
</blockquote>
<p>der grund war wohl nur eine falsche erinnerung. merke: niemals tipps ohne double-check geben.</p>
<p>die erinnerung war: push_back(x) ist gleich append(1, x) und +=(x) ist gleich append(string(1, x)), was auch stimmt, nur schreibt der standard eine implementation ja gar nicht fix fest.</p>
<p>btw. ein append nur für einen character gibt es nicht. (das ist nämlich push_back)</p>
<p>viel aufwand um nichts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1431583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1431583</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Sun, 06 Jan 2008 01:28:41 GMT</pubDate></item></channel></rss>