<?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[Frage zur Speicherverwaltung von char*-Strings]]></title><description><![CDATA[<p>Hallo Leute,<br />
ich hab da mal 'ne Frage:<br />
Also wenn ich schreibe</p>
<pre><code>char* Text = &quot;Text&quot;;
</code></pre>
<p>macht der Compiler daraus doch</p>
<pre><code>char* Text = new char[5];
Text[0] = 'T';
Text[1] = 'e';
Text[2] = 'x';
Text[3] = 't';
Text[4] = '\0';
</code></pre>
<p>Folglich müsste man doch, wenn die Variable Text z.B. dem Text eines Buttons dient und man den verändern will, nicht einfach</p>
<pre><code>char* Text = &quot;Text&quot;;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>schreiben sondern</p>
<pre><code>char* Text = &quot;Text&quot;;
delete[] Text;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>denn sonst gäbe es ein Speicherloch. Ist meine Überlegung richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/230962/frage-zur-speicherverwaltung-von-char-strings</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 02:40:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/230962.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Jan 2009 17:23:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zur Speicherverwaltung von char*-Strings on Sun, 04 Jan 2009 17:23:34 GMT]]></title><description><![CDATA[<p>Hallo Leute,<br />
ich hab da mal 'ne Frage:<br />
Also wenn ich schreibe</p>
<pre><code>char* Text = &quot;Text&quot;;
</code></pre>
<p>macht der Compiler daraus doch</p>
<pre><code>char* Text = new char[5];
Text[0] = 'T';
Text[1] = 'e';
Text[2] = 'x';
Text[3] = 't';
Text[4] = '\0';
</code></pre>
<p>Folglich müsste man doch, wenn die Variable Text z.B. dem Text eines Buttons dient und man den verändern will, nicht einfach</p>
<pre><code>char* Text = &quot;Text&quot;;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>schreiben sondern</p>
<pre><code>char* Text = &quot;Text&quot;;
delete[] Text;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>denn sonst gäbe es ein Speicherloch. Ist meine Überlegung richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1639388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1639388</guid><dc:creator><![CDATA[Mr Train]]></dc:creator><pubDate>Sun, 04 Jan 2009 17:23:34 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Speicherverwaltung von char*-Strings on Sun, 04 Jan 2009 17:31:16 GMT]]></title><description><![CDATA[<p>Nein! Du kannst (und sollst) kein Stringliteral löschen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1639395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1639395</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Sun, 04 Jan 2009 17:31:16 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Speicherverwaltung von char*-Strings on Sun, 04 Jan 2009 18:32:47 GMT]]></title><description><![CDATA[<p>Mr Train schrieb:</p>
<blockquote>
<p>Folglich müsste man doch, wenn die Variable Text z.B. dem Text eines Buttons dient und man den verändern will, nicht einfach</p>
<pre><code>char* Text = &quot;Text&quot;;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>schreiben sondern</p>
<pre><code>char* Text = &quot;Text&quot;;
delete[] Text;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>denn sonst gäbe es ein Speicherloch. Ist meine Überlegung richtig?</p>
</blockquote>
<p>Nein - ist sie nicht...</p>
<pre><code class="language-cpp">char *Text = &quot;Text&quot;;
//wird zu:
const char *symbol_1 = &quot;Text&quot;;
char *Text = const_cast &lt;char *&gt; (symbol_1);
</code></pre>
<p>und genau deshalb gibt es std::string:</p>
<pre><code class="language-cpp">#include &lt;string&gt;

std::string Text = &quot;Text&quot;;
Text = &quot;anderer Text&quot;;
</code></pre>
<p>bb</p>
<p>edit: const_cast &lt;char*&gt; hinzugefügt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1639399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1639399</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 04 Jan 2009 18:32:47 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Speicherverwaltung von char*-Strings on Sun, 04 Jan 2009 18:18:03 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>[...]</p>
</blockquote>
<p>Du hast den const_cast vergessen, der (leider) implizit durchgeführt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1639430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1639430</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Sun, 04 Jan 2009 18:18:03 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Speicherverwaltung von char*-Strings on Sun, 04 Jan 2009 18:33:55 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>[...]</p>
</blockquote>
<p>Du hast den const_cast vergessen, der (leider) implizit durchgeführt wird.</p>
</blockquote>
<p>Danke. Hab ihn mal ergänzt ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1639447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1639447</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 04 Jan 2009 18:33:55 GMT</pubDate></item></channel></rss>