<?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 zu strcat]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
char x[80];
char* y=&quot;Welt&quot;;
char* p=&quot;Hallo&quot;;
strcat(x,p);
strcat(x,y);

cout&lt;&lt;x;
}
</code></pre>
<p>Dieser Code führt zu einem Problem. Warum ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270895/frage-zu-strcat</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 18:02:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270895.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Jul 2010 22:40:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu strcat on Mon, 19 Jul 2010 22:40:50 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
char x[80];
char* y=&quot;Welt&quot;;
char* p=&quot;Hallo&quot;;
strcat(x,p);
strcat(x,y);

cout&lt;&lt;x;
}
</code></pre>
<p>Dieser Code führt zu einem Problem. Warum ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1928885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928885</guid><dc:creator><![CDATA[blurry333]]></dc:creator><pubDate>Mon, 19 Jul 2010 22:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Mon, 19 Jul 2010 22:51:31 GMT]]></title><description><![CDATA[<p><code>x[0]</code> bis <code>x[79]</code> ist uninitialisiert (undefinierte Werte).<br />
<code>strcat</code> orientiert sich beim Stringende an <code>\0</code> .<br />
Um das Problem zu lösen musst du den Char-Array mit <code>\0</code> initialisieren:</p>
<pre><code class="language-cpp">char x[80] = { '\0' };
</code></pre>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1928887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928887</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Mon, 19 Jul 2010 22:51:31 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 07:03:13 GMT]]></title><description><![CDATA[<p>In C++ reicht sogar folgendes:</p>
<pre><code class="language-cpp">char x[80] = { };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1928936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928936</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Tue, 20 Jul 2010 07:03:13 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 08:04:44 GMT]]></title><description><![CDATA[<p>blurry333 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int main()
{
char x[80];
char* y=&quot;Welt&quot;;
char* p=&quot;Hallo&quot;;
strcat(x,p);
strcat(x,y);

cout&lt;&lt;x;
}
</code></pre>
<p>Dieser Code führt zu einem Problem. Warum ?</p>
</blockquote>
<p>Die Begründung wurde ja schon genannt. Bessere Lösung ist aber</p>
<pre><code class="language-cpp">int main()
{
char x[80];
char* y=&quot;Welt&quot;;
char* p=&quot;Hallo&quot;;
strcpy(x,p);
strcat(x,y);

cout&lt;&lt;x;
}
</code></pre>
<p>strcpy erwartet kein initialisiertes char array.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1928968</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928968</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Tue, 20 Jul 2010 08:04:44 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 08:06:24 GMT]]></title><description><![CDATA[<p>Jetz bin ich aber enttäuscht von der &quot;besseren&quot; Lösung.<br />
Wie wärs mit std::string?</p>
<p>Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1928970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928970</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Tue, 20 Jul 2010 08:06:24 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 08:10:36 GMT]]></title><description><![CDATA[<p>theta schrieb:</p>
<blockquote>
<p>Jetz bin ich aber enttäuscht von der &quot;besseren&quot; Lösung.<br />
Wie wärs mit std::string?</p>
<p>Simon</p>
</blockquote>
<p>Das wäre aber Themaverfehlung, es ging dem Threadstarter um strcat. Ansonsten hast Du natürlich recht. Das ist i.d.R. noch besser.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1928973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928973</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Tue, 20 Jul 2010 08:10:36 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 08:19:11 GMT]]></title><description><![CDATA[<p>Wenn´s denn unbeding C sein muss würde ich eher strncpy und strncat benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1928978</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1928978</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 20 Jul 2010 08:19:11 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 09:28:46 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Wenn´s denn unbeding C sein muss würde ich eher strncpy und strncat benutzen.</p>
</blockquote>
<p>Ich denke weniger, dass ein Code mit <code>cout&lt;&lt;x;</code> C sein muss. Wahrscheinlich sind blurry333 lediglich die Vorteile von <code>std::string</code> gegenüber C-Strings noch nicht ganz bewusst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929018</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 20 Jul 2010 09:28:46 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 11:20:50 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>... Wahrscheinlich sind blurry333 lediglich die Vorteile von <code>std::string</code> gegenüber C-Strings noch nicht ganz bewusst.</p>
</blockquote>
<p>Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).<br />
Ist wieder ein Thema für Dogmatiker! :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929087</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929087</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Tue, 20 Jul 2010 11:20:50 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 11:33:49 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Nexus schrieb:</p>
<blockquote>
<p>... Wahrscheinlich sind blurry333 lediglich die Vorteile von <code>std::string</code> gegenüber C-Strings noch nicht ganz bewusst.</p>
</blockquote>
<p>Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).<br />
Ist wieder ein Thema für Dogmatiker! :p</p>
</blockquote>
<p>Falsch. Es geht hier nicht um eine konkrete Anwendung sondern um eine <strong>Übung</strong>. Es ist nicht verkehrt, <strong>auch</strong> solche Klassen wie std:string zu betrachten um dann, wenn es um eine konkrete Anwendung geht, souverän entscheiden zu können, was Sinn macht. Wenn ich bei Übungen nur strcpy und co anschaue, werde ich nie lernen, std:string einzusetzen auch, wenn es besser wäre.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929095</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Tue, 20 Jul 2010 11:33:49 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 12:20:25 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Nexus schrieb:</p>
<blockquote>
<p>... Wahrscheinlich sind blurry333 lediglich die Vorteile von <code>std::string</code> gegenüber C-Strings noch nicht ganz bewusst.</p>
</blockquote>
<p>Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).<br />
Ist wieder ein Thema für Dogmatiker! :p</p>
</blockquote>
<p>Ich schon. Du reservierst 80 Zeichen, wo du nur 10 brauchst. Immerhin eine Verschwendung von 700%. Und deine Definition auf <code>char c[10]</code> zu ändern, hilft nur sehr bedingt, denn sobald (wie fast immer) die Inhalte dynamisch werden (Usereingabe, Auslesen aus Datei etc.) kommt immer entweder der Fall vor, dass du zu wenig Platz hast und im schlimmsten Fall Pufferüberläufe provozierst, oder zu viel und damit Speicherverschwendung. Mit <code>std::string</code> hast du diese ganzen Probleme nicht.<br />
Vergleiche darüber hinaus auch die Lesbarkeit:</p>
<pre><code class="language-cpp">char x[10];
strcpy(x, &quot;Hallo&quot;);
strcat(x, &quot;Welt&quot;);

// vs

std::string x = &quot;Hallo&quot;;
x += &quot;Welt&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1929124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929124</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Tue, 20 Jul 2010 12:20:25 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 12:23:42 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Nexus schrieb:</p>
<blockquote>
<p>... Wahrscheinlich sind blurry333 lediglich die Vorteile von <code>std::string</code> gegenüber C-Strings noch nicht ganz bewusst.</p>
</blockquote>
<p>Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).<br />
Ist wieder ein Thema für Dogmatiker! :p</p>
</blockquote>
<p>Nein, sondern für Leute, die keine abstürzenden Programme haben wollen <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="😉"
    /></p>
<pre><code>int main()
{
  char x[8];
  char* y=&quot;Welt&quot;;
  char* p=&quot;Hallo&quot;;
  strcpy(x,p);
  strcat(x,y);

  cout&lt;&lt;x;
}
</code></pre>
<p>wird sicher zum Problem (wer findet den Fehler).</p>
<pre><code>int main()
{
  std::string y( &quot;Welt&quot; );
  std::string p( &quot;Hallo&quot; );
  std::string x = p + y;

  cout&lt;&lt;x;
}
</code></pre>
<p>geht einfach.</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929126</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929126</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Tue, 20 Jul 2010 12:23:42 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 12:39:55 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).<br />
Ist wieder ein Thema für Dogmatiker! :p</p>
</blockquote>
<p>Vom &quot;<em>Die ewig Gestrigen e.V.</em>&quot; habe ich schon mal was gehört.<br />
Kann man deinem Verein beitreten? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929137</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Tue, 20 Jul 2010 12:39:55 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 14:50:47 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<p>Vom &quot;<em>Die ewig Gestrigen e.V.</em>&quot; habe ich schon mal was gehört. Kann man deinem Verein beitreten? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p>Lass gut sein, auch ohne Verein. Die Smileys sind doch dazu da, mal etwas provokativ ausdrücken zu dürfen! :p Klar, schätze ich die Neuerungen von C++ gegenüber dem vorherigen C sehr und setze diese auch ein. Nur, wenn ich einzelne Strings bekannter Länge habe, die einmal initiert werden (z.B. AppName), dann mache ich das weiter mit einem C-String. Als nun mal fauler Mensch, wähle ich stets den einfachsten, kürzesten, und sichersten Weg.<br />
Ich habe allein etwas gegen die hier oft geäusserte Meinung: &quot;Das macht man heute nicht mehr so, ist kein C++, sondern veraltetes C!&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929213</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Tue, 20 Jul 2010 14:50:47 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 15:28:00 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Als nun mal fauler Mensch, wähle ich stets den einfachsten, kürzesten, und sichersten Weg.</p>
</blockquote>
<p>berniebutt schrieb:</p>
<blockquote>
<p>Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).</p>
</blockquote>
<p>Die beiden Aussagen passen nicht zusammen. <code>string c = a + b;</code> ist zweifellos einfacher, kürzer und sicherer als <code>char c[wievieleigentlich?]; strcpy(c, a); strcat(c, b);</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929232</guid><dc:creator><![CDATA[Nukularfüsiker]]></dc:creator><pubDate>Tue, 20 Jul 2010 15:28:00 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Tue, 20 Jul 2010 17:33:36 GMT]]></title><description><![CDATA[<p>berniebutt schrieb:</p>
<blockquote>
<p>Ich habe allein etwas gegen die hier oft geäusserte Meinung: &quot;Das macht man heute nicht mehr so, ist kein C++, sondern veraltetes C!&quot;</p>
</blockquote>
<p>Und aus reinem Trotz nimmst du also doch die veraltete Lösung mit mehr Nachteilen?</p>
<p>Ist ja nicht so, dass C-Strings immer die schlechtere Wahl sind. Z.B. für Literale nehme ich auch meist <code>const char*</code> . Aber sobald etwas mehr Operationen im Spiel sind, macht man sich das Leben mit <code>std::string</code> um einiges leichter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929284</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 20 Jul 2010 17:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu strcat on Wed, 21 Jul 2010 07:45:43 GMT]]></title><description><![CDATA[<p>blurry333 schrieb:</p>
<blockquote>
<p>[...]Dieser Code führt zu einem Problem. Warum ?</p>
</blockquote>
<p>berniebutt schrieb:</p>
<blockquote>
<p>[...]Ich sehe in diesem einfachen Beispiel keine Vorteile von C++ (std::string) gegenüber C (strcpy, strcat).<br />
Ist wieder ein Thema für Dogmatiker! :p</p>
</blockquote>
<p>Tja...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929426</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 21 Jul 2010 07:45:43 GMT</pubDate></item></channel></rss>