<?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[Anfängerfrage]]></title><description><![CDATA[<pre><code class="language-cpp">#include&lt;iostream.h&gt;

typedef  int Int ;

class String{
public:
 String(){St = new char[2]; Len = 1;}

 String(const char* rhs){Len = strlen(rhs);St= new char[Len+1]; 
      for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i];}St[Len] = '\0'; }

 String(const String&amp; rhs) {Len=rhs.GetLen(); St= new char[Len+1L]; 
     for(Int i(0); i&lt;Len; ++i){St[i] = rhs[i];} St[Len] = '\0';  }

 ~String() {Len =0;delete [] this-&gt;St;}

operator char*() const {return St;}

char&amp; operator[](Int a)const {  return St[a]; }

String&amp; operator=(const String rhs)
              {if(this==&amp;rhs) {return (*this);} 
               Len = rhs.GetLen(); delete[] St; St = new char[Len+1];
               for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i]; }St[Len] = '\0';        
               return (*this);}

String&amp; operator=( const char* rhs)
             {delete[]St; St= new char[Len+1]; Len = strlen(rhs); 
              for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i];} St[Len] = '\0';                             
              return (*this);          }

Int GetLen() const {return Len;}

private:

char* St;
Int Len;

};

String aaa;
void  f(){

aaa = &quot;&lt;tr&gt;\n&quot;
          &quot;&lt;td align=\&quot;center\&quot;&gt;Mündlich&lt;/td&gt;\n&quot;
         &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbsp;&lt;/td&gt;\n&quot;
          &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbsp;&lt;/td&gt;\n&quot;
           &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbsp;&lt;/td&gt;\n&quot;
            &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbbsp;&lt;/td&gt;\n&quot;;

}

int main()
{

f();

cout&lt;&lt;aaa;

return 0;
}
</code></pre>
<p>Wollte mal versuchen, eine eigene Stringklasse zu schreiben..<br />
Ich verstehe einfach nicht, warum es immer abstürzt<br />
Ist wahrscheinlich ein ganz dummer Fehler</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/124612/anfängerfrage</link><generator>RSS for Node</generator><lastBuildDate>Mon, 24 Aug 2026 01:37:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/124612.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Oct 2005 11:44:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 11:44:26 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include&lt;iostream.h&gt;

typedef  int Int ;

class String{
public:
 String(){St = new char[2]; Len = 1;}

 String(const char* rhs){Len = strlen(rhs);St= new char[Len+1]; 
      for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i];}St[Len] = '\0'; }

 String(const String&amp; rhs) {Len=rhs.GetLen(); St= new char[Len+1L]; 
     for(Int i(0); i&lt;Len; ++i){St[i] = rhs[i];} St[Len] = '\0';  }

 ~String() {Len =0;delete [] this-&gt;St;}

operator char*() const {return St;}

char&amp; operator[](Int a)const {  return St[a]; }

String&amp; operator=(const String rhs)
              {if(this==&amp;rhs) {return (*this);} 
               Len = rhs.GetLen(); delete[] St; St = new char[Len+1];
               for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i]; }St[Len] = '\0';        
               return (*this);}

String&amp; operator=( const char* rhs)
             {delete[]St; St= new char[Len+1]; Len = strlen(rhs); 
              for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i];} St[Len] = '\0';                             
              return (*this);          }

Int GetLen() const {return Len;}

private:

char* St;
Int Len;

};

String aaa;
void  f(){

aaa = &quot;&lt;tr&gt;\n&quot;
          &quot;&lt;td align=\&quot;center\&quot;&gt;Mündlich&lt;/td&gt;\n&quot;
         &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbsp;&lt;/td&gt;\n&quot;
          &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbsp;&lt;/td&gt;\n&quot;
           &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbsp;&lt;/td&gt;\n&quot;
            &quot;&lt;td align=\&quot;center\&quot;&gt;&amp;nbbsp;&lt;/td&gt;\n&quot;;

}

int main()
{

f();

cout&lt;&lt;aaa;

return 0;
}
</code></pre>
<p>Wollte mal versuchen, eine eigene Stringklasse zu schreiben..<br />
Ich verstehe einfach nicht, warum es immer abstürzt<br />
Ist wahrscheinlich ein ganz dummer Fehler</p>
]]></description><link>https://www.c-plusplus.net/forum/post/903315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903315</guid><dc:creator><![CDATA[alwa]]></dc:creator><pubDate>Sat, 29 Oct 2005 11:44:26 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 11:54:37 GMT]]></title><description><![CDATA[<p>Mit was für einer Fehlermeldung stürzt er denn ab?</p>
<p>Ein paar kleinere Stolpersteine:<br />
* formatier' den Code etwas besser (gerade die &quot;St[Len]='\0';&quot; am Zeilenende erschweren das Lesen).<br />
* ist es Absicht, daß du im Copy-Ctor plötzlich long (1L) verwendest?<br />
* der Inhalt eines Default-konstruierten Strings ist undefiniert.<br />
* im operator=(const char*) solltest du erst die Länge berechnen und dann deinen Speicher reservieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/903317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903317</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sat, 29 Oct 2005 11:54:37 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 12:01:01 GMT]]></title><description><![CDATA[<p>Ich weiß der code ist nicht so toll, aber er müsste doch funktionieren.</p>
<p>Es ist keine Compiler Fehlermeldung, sondern das Programm stürzt zur Laufzeit mit<br />
&quot;xxx hat ein Problem festgestellt und muss beendet werden.&quot; ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/903324</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903324</guid><dc:creator><![CDATA[alwa]]></dc:creator><pubDate>Sat, 29 Oct 2005 12:01:01 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 12:08:45 GMT]]></title><description><![CDATA[<p>du musst erst die länge errechenen dann speicher bereit stellen <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="😉"
    /><br />
bei deinem op = forderst du nur zwei byte an</p>
<pre><code class="language-cpp">String&amp; operator=( const char* rhs)
{
	delete[]St;
	Len = strlen(rhs);
	St= new char[Len+1];

       for(Int i(0); i&lt;Len; ++i) {St[i] = rhs[i];} St[Len] = '\0';
return (*this);
}
</code></pre>
<p>[edit]<br />
tags</p>
]]></description><link>https://www.c-plusplus.net/forum/post/903333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903333</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Sat, 29 Oct 2005 12:08:45 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 12:09:33 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>* im operator=(const char*) solltest du erst die Länge berechnen und dann deinen Speicher reservieren.</p>
</blockquote>
<p>^^ das da dürfte dein Problem sein: Du legst einen Speicher für zwei chars an (Len wurde im Default-Ctor auf 1 gesetzt) und versuchst anschließend, ca. 100 chars in diesen Bereich reinzuquetschen - damit schreibst du in einen Bereich, der dir nicht gehört (und den womöglich cout für sich reservieren wollte).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/903334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903334</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sat, 29 Oct 2005 12:09:33 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 12:13:04 GMT]]></title><description><![CDATA[<p>DANKE DANKE DANKE DANKE DANKE DANKE DANKE DANKE DANKE DANKE DANKE DANKE</p>
]]></description><link>https://www.c-plusplus.net/forum/post/903337</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903337</guid><dc:creator><![CDATA[alwa]]></dc:creator><pubDate>Sat, 29 Oct 2005 12:13:04 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sat, 29 Oct 2005 13:59:35 GMT]]></title><description><![CDATA[<p>alwa schrieb:</p>
<blockquote>
<pre><code class="language-cpp">typedef  int Int ;
</code></pre>
</blockquote>
<p>Wäre doch eigentlich was für thedailywtf. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/903406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/903406</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sat, 29 Oct 2005 13:59:35 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Sun, 30 Oct 2005 23:08:04 GMT]]></title><description><![CDATA[<p>weiß zwar nicht was thedailywtf ist, aber typedef int Int habe nur gemacht, weil ich ne eigene int Klasse gemacht habe, die ich nicht mitkopieren wollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904202</guid><dc:creator><![CDATA[alwa]]></dc:creator><pubDate>Sun, 30 Oct 2005 23:08:04 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Mon, 31 Oct 2005 10:04:03 GMT]]></title><description><![CDATA[<p><a href="http://it-administrator.de/aktuell/13229.html" rel="nofollow">http://it-administrator.de/aktuell/13229.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/904347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904347</guid><dc:creator><![CDATA[eiskaltalsgast]]></dc:creator><pubDate>Mon, 31 Oct 2005 10:04:03 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Mon, 31 Oct 2005 10:15:57 GMT]]></title><description><![CDATA[<p>alwa schrieb:</p>
<blockquote>
<p>weiß zwar nicht was thedailywtf ist, aber typedef int Int habe nur gemacht, weil ich ne eigene int Klasse gemacht habe, die ich nicht mitkopieren wollte.</p>
</blockquote>
<p>Bloß als Vorschlag: Nenn deine Klassen nicht wie built-ins, das führt mit Sicherheit ins Chaos.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/904356</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904356</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Mon, 31 Oct 2005 10:15:57 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerfrage on Mon, 31 Oct 2005 12:48:42 GMT]]></title><description><![CDATA[<p>alwa schrieb:</p>
<blockquote>
<p>weiß zwar nicht was thedailywtf ist, aber typedef int Int habe nur gemacht, weil ich ne eigene int Klasse gemacht habe, die ich nicht mitkopieren wollte.</p>
</blockquote>
<p>War ja auch nicht böse gemeint, wirkte nur etwas komisch. <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/904479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/904479</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Mon, 31 Oct 2005 12:48:42 GMT</pubDate></item></channel></rss>