<?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[Kleine String Klasse]]></title><description><![CDATA[<p>Hallo ich muss für Informatik eine kleine Stringklasse schreiben, komme aber nicht weiter :</p>
<p>String test(&quot;123&quot;);<br />
String test2(&quot;45&quot;);</p>
<p>test = test + test2;</p>
<p>Jetzt sollte eigentlich in test &quot;12345&quot; und in test2 &quot;45&quot; stehen. Aber es steht in beiden &quot;12345&quot;.</p>
<p>Hier der Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;

using namespace std;

namespace dk
{
    class String
    {
      private:

        char* data;
        int length;
        int data_size; //length + 1

      public:

        String()
        {
            length = 0;
            data_size = 0;
            data = 0;
        }

        String(char* data,int length = -1) //if length == -1 ,strlen() will find out.
        {                                   //length parameter is used for strings where 0 bytes aren`t only at the end

             if(length == -1) this-&gt;length = strlen(data);
             else this-&gt;length = length;
           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        ~String()
        {
           delete[] this-&gt;data;
        }

        String(const String&amp; org)
        {
            data = new char[org.data_size];
            strcpy(data,org.data);
            length = org.length;
            data_size = org.data_size;
        }

        void operator=(const char* data)
        {
           delete[] this-&gt;data;
           this-&gt;length = strlen(data);
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
        }

        String&amp; operator+(const String&amp; other)
        {
           char* old_data = new char[data_size];
           strcpy(old_data,data);
           delete[] data;
           length += other.length;
           data = new char[length+1];
           strcpy(data,old_data);
           delete[] old_data;
           strcat(data,other.data);
           data[length] = '\0';
           data_size = length+1;
           return *this;
        }

        void operator=(const String&amp; other)
        {
           delete[] this-&gt;data;
           this-&gt;length = other.length;
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,other.data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
        }

        void assign(const char* data,int length = -1) //the same as operator=() but with length parameter
        {
           delete[] this-&gt;data;

             if(length == -1)
             {
                this-&gt;length = strlen(data);
             }
             else this-&gt;length = length;

           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        const char* c_str() const
        {
            if(data)
            return this-&gt;data;
            else return &quot;&quot;;
        }

        char* g_dat() //if needed, data can be modified
        {
            if(data)
            return this-&gt;data;
            else return &quot;ERROR g_dat()!&quot;;
        }

        int size()
        {
            return this-&gt;data_size;
        }

        int len()
        {
            return this-&gt;length;
        }
    };
}

using namespace dk;

int main()
{
    String test(&quot;123&quot;);
    String test2(&quot;m&quot;);
    String test3;

    test2 = test + test2;
    test3 = &quot;blabla&quot;;

    cout &lt;&lt; test2.c_str()  &lt;&lt; endl &lt;&lt; test3.c_str() &lt;&lt; endl;
    cout &lt;&lt; test.size() &lt;&lt; endl &lt;&lt; test.c_str() &lt;&lt; endl &lt;&lt; test2.size() &lt;&lt; endl &lt;&lt; test2.c_str() &lt;&lt; endl;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/307899/kleine-string-klasse</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 08:08:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307899.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Sep 2012 12:20:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 12:20:20 GMT]]></title><description><![CDATA[<p>Hallo ich muss für Informatik eine kleine Stringklasse schreiben, komme aber nicht weiter :</p>
<p>String test(&quot;123&quot;);<br />
String test2(&quot;45&quot;);</p>
<p>test = test + test2;</p>
<p>Jetzt sollte eigentlich in test &quot;12345&quot; und in test2 &quot;45&quot; stehen. Aber es steht in beiden &quot;12345&quot;.</p>
<p>Hier der Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;

using namespace std;

namespace dk
{
    class String
    {
      private:

        char* data;
        int length;
        int data_size; //length + 1

      public:

        String()
        {
            length = 0;
            data_size = 0;
            data = 0;
        }

        String(char* data,int length = -1) //if length == -1 ,strlen() will find out.
        {                                   //length parameter is used for strings where 0 bytes aren`t only at the end

             if(length == -1) this-&gt;length = strlen(data);
             else this-&gt;length = length;
           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        ~String()
        {
           delete[] this-&gt;data;
        }

        String(const String&amp; org)
        {
            data = new char[org.data_size];
            strcpy(data,org.data);
            length = org.length;
            data_size = org.data_size;
        }

        void operator=(const char* data)
        {
           delete[] this-&gt;data;
           this-&gt;length = strlen(data);
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
        }

        String&amp; operator+(const String&amp; other)
        {
           char* old_data = new char[data_size];
           strcpy(old_data,data);
           delete[] data;
           length += other.length;
           data = new char[length+1];
           strcpy(data,old_data);
           delete[] old_data;
           strcat(data,other.data);
           data[length] = '\0';
           data_size = length+1;
           return *this;
        }

        void operator=(const String&amp; other)
        {
           delete[] this-&gt;data;
           this-&gt;length = other.length;
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,other.data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
        }

        void assign(const char* data,int length = -1) //the same as operator=() but with length parameter
        {
           delete[] this-&gt;data;

             if(length == -1)
             {
                this-&gt;length = strlen(data);
             }
             else this-&gt;length = length;

           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        const char* c_str() const
        {
            if(data)
            return this-&gt;data;
            else return &quot;&quot;;
        }

        char* g_dat() //if needed, data can be modified
        {
            if(data)
            return this-&gt;data;
            else return &quot;ERROR g_dat()!&quot;;
        }

        int size()
        {
            return this-&gt;data_size;
        }

        int len()
        {
            return this-&gt;length;
        }
    };
}

using namespace dk;

int main()
{
    String test(&quot;123&quot;);
    String test2(&quot;m&quot;);
    String test3;

    test2 = test + test2;
    test3 = &quot;blabla&quot;;

    cout &lt;&lt; test2.c_str()  &lt;&lt; endl &lt;&lt; test3.c_str() &lt;&lt; endl;
    cout &lt;&lt; test.size() &lt;&lt; endl &lt;&lt; test.c_str() &lt;&lt; endl &lt;&lt; test2.size() &lt;&lt; endl &lt;&lt; test2.c_str() &lt;&lt; endl;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2249548</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249548</guid><dc:creator><![CDATA[string master]]></dc:creator><pubDate>Sat, 08 Sep 2012 12:20:20 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 12:22:10 GMT]]></title><description><![CDATA[<p>Ach ja und das mit dem length Parameter ist,weil wir da später mal binärdaten speichern wollen,die nicht nur am Ende ein 0Byte haben und strlen() würde nur bis zum 0Byte zählen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249549</guid><dc:creator><![CDATA[string master]]></dc:creator><pubDate>Sat, 08 Sep 2012 12:22:10 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 12:40:26 GMT]]></title><description><![CDATA[<p>guck dir deinen operator+ nochmal genauer an. is das wirklich das was du machen willst ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249557</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sat, 08 Sep 2012 12:40:26 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 12:41:16 GMT]]></title><description><![CDATA[<p>Du darfst doch in <code>operator+()</code> dein Objekt nicht ändern...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249558</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Sat, 08 Sep 2012 12:41:16 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 13:29:15 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;

using namespace std;

namespace dk
{
    class String
    {
      private:

        char* data;
        int length;                        // ein vorzeichenloser Typ dürfte sinnvoller sein
        int data_size;  

      public:

        String()                           // die Verwendung der Initialisierungsliste ist zweckmäßig
        {
            length = 0;
            data_size = 0;
            data = 0;
        }

        String(char* data,int length = -1) // Überladung sollte in Erwägung gezogen werden, da die Bedeutung der verscheidenen Aufrufe doch recht stark varriert
        {                                  // wiederum: Intialisierungsliste verwenden

             if(length == -1) this-&gt;length = strlen(data);
             else this-&gt;length = length;
           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);     // das ist die falsche Funktion, falls der zu kopierende String eingebette '\0' enthält
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        ~String()
        {
           delete[] this-&gt;data;
        }

        String(const String&amp; org)
        {
            data = new char[org.data_size];
            strcpy(data,org.data);                    // falsche Funktion, falls '\0' im String
            length = org.length;
            data_size = org.data_size;
        }

        void operator=(const char* data)              // Rügabe überdenken
        {
           delete[] this-&gt;data;                       // evtl. auch den Fall a = a.c_str() beachten!; nicht exception-sicher, falls
           this-&gt;length = strlen(data);
           this-&gt;data = new char[length+1];           // hier eine Exception ausgelöst wird, ist der Inhalt von data unbestimmt, der folgende Destruktoraufruf hat folglich UB
           strncpy(this-&gt;data,data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
        }

        String&amp; operator+(const String&amp; other)        // Rückgabewert überdenken; Funktion sollte const sein
        {
           char* old_data = new char[data_size];
           strcpy(old_data,data);
           delete[] data;                             // wieso nicht gleich old_data = data?
           length += other.length;
           data = new char[length+1];
           strcpy(data,old_data);                     // '\0' im String...
           delete[] old_data;
           strcat(data,other.data);                   // '\0' im String
           data[length] = '\0';
           data_size = length+1;
           return *this;                              
        }                                             // op+= in Betracht ziehen und Implementierung über + (oder umgekehrt, ist aber bei Strings wenig sinnvoll)

        void operator=(const String&amp; other)           // Rückgabewert überdenken
        {
           delete[] this-&gt;data;                       // Selbstzuweisung beachten !!!
           this-&gt;length = other.length;
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,other.data,length);     // '\0' im String
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
        }                                             // an copy&amp;swap denken

        void assign(const char* data,int length = -1) //the same as operator=() but with length parameter
        {
           delete[] this-&gt;data;                       // siehe oben: a.assign(a.c_str()); nicht exception-sicher

             if(length == -1)
             {
                this-&gt;length = strlen(data);
             }
             else this-&gt;length = length;

           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);     // '\0' im String
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        const char* c_str() const
        {
            if(data)
            return this-&gt;data;
            else return &quot;&quot;;
        }

        char* g_dat() //if needed, data can be modified
        {
            if(data)
            return this-&gt;data;
            else return &quot;ERROR g_dat()!&quot;;             // illegal in C++11; ganz schlechte Idee sowieso, weil der Aufrufer keine Möglichkeit hat, zu erkennen, dass ein Fehler aufgetreten ist
                                                      // direkte Rückgabe von data oder eine Exception erscheinen zweckmäßiger
        }

        int size()                                    // const
        {
            return this-&gt;data_size;
        }

        int len()                                    // const
        {
            return this-&gt;length;
        }
    };
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2249563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249563</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 08 Sep 2012 13:29:15 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 15:58:23 GMT]]></title><description><![CDATA[<p>Vielen Dank für eure Vorschläge (vor allem an camper).</p>
<blockquote>
<p>Du darfst doch in operator+() dein Objekt nicht ändern...</p>
</blockquote>
<p>Also muss ich eine Kopie erstellen?</p>
<blockquote>
<p>strncpy(this-&gt;data,data,this-&gt;length); // das ist die falsche Funktion, falls der zu kopierende String eingebette '\0' enthält</p>
</blockquote>
<p>Ah ok, dann muss ich mir diese Funtkion selbst schreiben.</p>
<blockquote>
<p>// illegal in C++11; ganz schlechte Idee sowieso, weil der Aufrufer keine Möglichkeit hat, zu erkennen, dass ein Fehler aufgetreten ist<br />
// direkte Rückgabe von data oder eine Exception erscheinen zweckmäßiger</p>
</blockquote>
<p>Ich habe versucht data direkt zurückzugeben, aber dann tritt ein Fehler auf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249582</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249582</guid><dc:creator><![CDATA[string master]]></dc:creator><pubDate>Sat, 08 Sep 2012 15:58:23 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 16:06:39 GMT]]></title><description><![CDATA[<p>string master schrieb:</p>
<blockquote>
<p>Ich habe versucht data direkt zurückzugeben, aber dann tritt ein Fehler auf.</p>
</blockquote>
<p>Was denn für ein Fehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249584</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Sat, 08 Sep 2012 16:06:39 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sat, 08 Sep 2012 17:10:31 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">String operator+(const String&amp; other) const
        {
           String result(c_str(), size()+other.size());
           memcpy(result.g_dat()+size(), other.c_str(), other.size());
           return result;
        }
</code></pre>
<p>setzt allerdings den Konstruktor in seiner gegenwärtig defekten Form voraus <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2249597</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249597</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 08 Sep 2012 17:10:31 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Sun, 09 Sep 2012 12:02:41 GMT]]></title><description><![CDATA[<p>Ich hab jetzt das nochmal überarbeitet (außer strcpy mit 0Byte). Habt ihr noch Verbesserungsvorschläge? (Bis Mittwoch muss ich fertig sein).</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstring&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;bitset&gt;
#include &lt;algorithm&gt;

using namespace std;

namespace dk
{

    class String
    {
      private:

        char* data;
        unsigned int length;
        unsigned int data_size; //length + 1

      public:

      friend ostream&amp; operator&lt;&lt;(ostream &amp;os,const String &amp;str);
      friend istream&amp; operator&gt;&gt;(istream &amp;is,String &amp;str);

        String() : length(0),data_size(0)
        {
            data = 0;
        }

        String(const char* data,int length = -1) //if length == -1 ,strlen() will find out.
        {                                   //length parameter is used for strings where 0 bytes aren`t only at the end

             if(length == -1) this-&gt;length = strlen(data);
             else this-&gt;length = length;
           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        String(string data)
        {
           this-&gt;length = data.size();
           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data.c_str(),this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        String(const int freq,const char letter) : length(freq)
        {
            data = new char[freq+1];
            memset(data,letter,freq);
            data_size = length+1;
            data[length] = '\0';
        }

        ~String()
        {
           delete[] this-&gt;data;
        }

        String(const String&amp; org)
        {
            data = new char[org.data_size];
            strcpy(data,org.data);
            length = org.length;
            data_size = org.data_size;
        }

        const String&amp; operator=(const char* data)
        {
           delete[] this-&gt;data;
           this-&gt;length = strlen(data);
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
           return *this;
        }

        const String&amp; operator=(const String&amp; other)
        {
           delete[] this-&gt;data;
           this-&gt;length = other.length;
           this-&gt;data = new char[length+1];
           strncpy(this-&gt;data,other.data,length);
           this-&gt;data[length] = '\0';
           this-&gt;data_size = length+1;
           return *this;
        }

        const String operator+(const String&amp; other)
        {
           String ret(&quot;&quot;,length+other.length);
           strcpy(ret.data,data);
           strcat(ret.data,other.data);
           ret.data[ret.length] = '\0';
           return ret;
        }

        const String operator+(const char* other)
        {
           String ret(&quot;&quot;,length+strlen(other));
           strcpy(ret.data,data);
           strcat(ret.data,other);
           ret.data[ret.length] = '\0';
           return ret;
        }

        const String&amp; operator+=(const String&amp; other)
        {
           *this = operator+(other);
           return *this;
        }

        const String&amp; operator+=(const char* other)
        {
           *this = operator+(other);
           return *this;
        }

        void assign(const char* data,int length = -1) //the same as operator=() but with length parameter
        {
           delete[] this-&gt;data;

             if(length == -1)
             {
                this-&gt;length = strlen(data);
             }
             else this-&gt;length = length;

           this-&gt;data = new char[this-&gt;length+1];
           strncpy(this-&gt;data,data,this-&gt;length);
           this-&gt;data[this-&gt;length] = '\0';
           this-&gt;data_size = this-&gt;length+1;
        }

        void crypt(const char* key)
        {
            unsigned int keylen = strlen(key);
            unsigned int k = 0;
            string reverser;

            for(unsigned int i=0;i&lt;length;i++)
            {
                if(k == keylen) k = 0;
                data[i] = data[i] ^ key[k];
                data[i] += key[k];
                k++;
            }

            for(unsigned int i=0;i&lt;length-2;i++)
            {
                char swap;
                swap = data[i];
                data[i] = data[i+2];
                data[i+2] = swap;
            }

            reverser = data;
            reverse(reverser.begin(),reverser.end());
            strcpy(data,reverser.c_str());
        }

        void decrypt(const char* key)
        {
            unsigned int keylen = strlen(key);
            unsigned int k = 0;

            string reverser = data;
            reverse(reverser.begin(),reverser.end());
            strcpy(data,reverser.c_str());

            for(unsigned int i=length-1;i&gt;1;i--)
            {
                char swap;
                swap = data[i];
                data[i] = data[i-2];
                data[i-2] = swap;
            }

            for(unsigned int i=0;i&lt;length;i++)
            {
                if(k == keylen) k = 0;
                data[i] -= key[k];
                data[i] = data[i] ^ key[k];
                k++;
            }
        }

        void reserve(unsigned int len)
        {
            length = len;
            data_size = len+1;
            delete[] data;
            data = new char[data_size];
            memset(data,0,data_size);
        }

        int find(const char letter)
        {
            for(unsigned int i=0;i&lt;length;i++)
            {
                if(data[i] == letter) return i;
            }

            return -1;
        }

        int find(const char* text)
        {
            char* pointer = strstr(data,text);
            if(pointer == 0) return -1;

            return pointer - data;
        }

        const char* c_str() const
        {
            if(data)
            return this-&gt;data;
            else return &quot;&quot;;
        }

        char* g_dat() //if needed, data can be modified
        {
            if(data)
            return this-&gt;data;
           // else return &quot;&quot;; //EXECPTION HIER EINFÜGEN
        }

        int size()
        {
            return this-&gt;data_size;
        }

        int len()
        {
            return this-&gt;length;
        }

        template &lt;typename T&gt;
        T convert(__int8 base = -1)
        {
            T output;
            stringstream wan;

              if(base == 16)
                wan &lt;&lt; hex &lt;&lt; data;
              else if (base == 8)
                wan &lt;&lt; oct &lt;&lt; data;
              else wan &lt;&lt; data;

            wan &gt;&gt; output;
            return output;
        }
    };

    template &lt;class T,class Z&gt;
    const Z convert(T in)
    {
        Z output;
        stringstream wan;
        wan &lt;&lt; in;
        wan &gt;&gt; output;
        return output;
    }

    ostream&amp; operator&lt;&lt;(ostream &amp;os,const String &amp;str)
    {
      os &lt;&lt; str.data;
      return os;
    }

    istream&amp; operator&gt;&gt;(istream &amp;is,String &amp;str)
    {
      string buffer;
      is &gt;&gt; buffer;
      str = buffer.c_str();
      return is;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2249703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249703</guid><dc:creator><![CDATA[string master]]></dc:creator><pubDate>Sun, 09 Sep 2012 12:02:41 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Mon, 10 Sep 2012 08:20:40 GMT]]></title><description><![CDATA[<p>Musst du einen char* verwenden? Da es eine Informatik-Übung ist, vermutlich schon...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249843</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Mon, 10 Sep 2012 08:20:40 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Mon, 10 Sep 2012 08:53:33 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">String() : length(0),data_size(0)
        {
            data = 0; // Initialisierungsliste...
        }
</code></pre>
<pre><code class="language-cpp">String&amp; operator=(......)
{
   return *this;
}
</code></pre>
<p>Ansonsten sehe ich Codezeilen die öfters vorkommen. Die könntest du noch in eine Funktion auslagern, sodass du schlußendlich keine redundanten Codezeilen mehr hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2249852</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2249852</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Mon, 10 Sep 2012 08:53:33 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Mon, 10 Sep 2012 18:19:45 GMT]]></title><description><![CDATA[<p>Ok danke, ich werd euch dann sagen, welche Note ich bekommen habe ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2250054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250054</guid><dc:creator><![CDATA[string master]]></dc:creator><pubDate>Mon, 10 Sep 2012 18:19:45 GMT</pubDate></item><item><title><![CDATA[Reply to Kleine String Klasse on Tue, 11 Sep 2012 08:31:39 GMT]]></title><description><![CDATA[<p>Nochmal zusammenfassend und ergänzend:</p>
<ul>
<li>Schau Dir nochmal Copy&amp;swap für <code>operator=()</code> an</li>
<li>Dazu: Was ist momentan mit Selbstzuweisung? ( <code>String s = &quot;bla&quot;; s = s;</code> )</li>
<li>Was passiert, wenn Du einen default-konstruierten String ausgibst?</li>
<li>operator+() sollte freie Funktion sein</li>
<li>ist diese doppelte Buchführung ( <code>length</code> u. <code>length+1</code> (aka. <code>data_size</code> )) notwendig?</li>
<li>Benutz duchgehend initialisierungslisten in den Konstruktoren (geht auch mit new[])</li>
<li>zuviel const bei den Rückgabewerten</li>
<li>zuwenig const in den Signaturen ( <code>size(), find()...</code> )</li>
<li>wenn Du eh binäre strings speichern willst, sind die str*-Funktionen aus C die falsche Wahl</li>
<li>DRY!</li>
<li>Nimm Überladung, bevor Du solche Krücken wie <code>if (length == -1)...</code> benutzt</li>
<li>die Ein-/Ausgabeoperatoren müssen keine friends sein</li>
</ul>
]]></description><link>https://www.c-plusplus.net/forum/post/2250173</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2250173</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Tue, 11 Sep 2012 08:31:39 GMT</pubDate></item></channel></rss>