<?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[löschen von array of chars (string) schlägt fehl]]></title><description><![CDATA[<p>Hallo also ich definniere im Code einen String:</p>
<p>char* help_string = new char[9];<br />
help_string = &quot;Ressource&quot;;</p>
<p>diesen string will ich nach nutzung löschen, aber:</p>
<p>delete []help_string;</p>
<p>oder nur:<br />
delete help_string;</p>
<p>schlägt in VS 2008 fehl (schaden am heap)</p>
<p>weiss jemand rat?</p>
<p>der string char wird in einer funktion genutzt, ist nach ablauf der funktion der speicher vielleicht automatisch freigegeben.</p>
<p>grüße und dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/268417/löschen-von-array-of-chars-string-schlägt-fehl</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 21:04:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/268417.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 08 Jun 2010 20:03:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to löschen von array of chars (string) schlägt fehl on Tue, 08 Jun 2010 20:03:10 GMT]]></title><description><![CDATA[<p>Hallo also ich definniere im Code einen String:</p>
<p>char* help_string = new char[9];<br />
help_string = &quot;Ressource&quot;;</p>
<p>diesen string will ich nach nutzung löschen, aber:</p>
<p>delete []help_string;</p>
<p>oder nur:<br />
delete help_string;</p>
<p>schlägt in VS 2008 fehl (schaden am heap)</p>
<p>weiss jemand rat?</p>
<p>der string char wird in einer funktion genutzt, ist nach ablauf der funktion der speicher vielleicht automatisch freigegeben.</p>
<p>grüße und dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1909187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1909187</guid><dc:creator><![CDATA[greenghecco]]></dc:creator><pubDate>Tue, 08 Jun 2010 20:03:10 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von array of chars (string) schlägt fehl on Tue, 08 Jun 2010 20:11:27 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Als erstes bitte benutzte doch die C++-Tags, damit kann man den Quellcode einfacher lessen.</p>
<p>Und ja dein Problem liegt an dieser stelle:</p>
<p>greenghecco schrieb:</p>
<blockquote>
<p>Hallo also ich definniere im Code einen String:</p>
<pre><code class="language-cpp">char* help_string = new char[9];
help_string = &quot;Ressource&quot;;  // Hier verschiebst du deinen Pointer auf einen Konstanten Bereich
</code></pre>
</blockquote>
<p>Mit der Zuweisung verschiebst du den Pointer und kopierst nicht wie du wahrscheinlich vorhattest.<br />
Damit generierst du auch noch zusätzlich ein Speicherleck, da du nach der Zweisung auch die Addresse<br />
zu deinen Dynamisch erzeugten Speicher &quot;vergessen&quot; hast.</p>
<p>Das kopieren müsste dann so ausschauen:</p>
<pre><code class="language-cpp">strncpy( help_string, &quot;Ressource&quot;, 8 );
</code></pre>
<p>Dann kannst du auch wieder ganz normal mit</p>
<pre><code class="language-cpp">delete []help_string;
</code></pre>
<p>dein Char-Array löschen</p>
<p>Mfg Marco</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1909194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1909194</guid><dc:creator><![CDATA[Marc-O]]></dc:creator><pubDate>Tue, 08 Jun 2010 20:11:27 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von array of chars (string) schlägt fehl on Tue, 08 Jun 2010 20:34:09 GMT]]></title><description><![CDATA[<p>super vielen dank für die erklärung.</p>
<p>Ist das mit der 8 nur n tippfehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1909202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1909202</guid><dc:creator><![CDATA[greenghecco]]></dc:creator><pubDate>Tue, 08 Jun 2010 20:34:09 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von array of chars (string) schlägt fehl on Tue, 08 Jun 2010 20:52:57 GMT]]></title><description><![CDATA[<p>Jap <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Tippfehler sollte ne 9 sein, wobei ein strlen(const char*) noch einfacher wäre. Nur macht dies bei Konstanten<br />
keinen Sinn sonst hast diese ja gleich 2 mal drin.</p>
<p>Mfg marco</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1909208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1909208</guid><dc:creator><![CDATA[Marc-O]]></dc:creator><pubDate>Tue, 08 Jun 2010 20:52:57 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von array of chars (string) schlägt fehl on Tue, 08 Jun 2010 21:22:34 GMT]]></title><description><![CDATA[<p>Benutze einfach std::string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1909222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1909222</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Tue, 08 Jun 2010 21:22:34 GMT</pubDate></item></channel></rss>