<?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[String-Klasse]]></title><description><![CDATA[<p>Hallo, ich habe zu Studienzwecken eine eigene string-Klasse geschrieben. Jetzt würde ich gerne wissen, ob man daran noch etwas verbessern kann, bzw. ob da noch Fehler drin sind.<br />
Es wäre freundlich, wenn ihr euch das mal angucken könntet und mir eine Rückmeldug geben würdet, was man noch verbessern, verändern etc. sollte.</p>
<p>Hier der header der String-Klasse:</p>
<pre><code class="language-cpp">class String
{
private:
	char* StrText;
	int Length;
public:
	int GetLength();
	String&amp; operator=(const String&amp; strtext);
	char&amp; operator[](int pos);

	String SubStr(int posstart, int posend);

	String(char* strtext = &quot;&quot;);
	String(const String&amp; strtext);	

	virtual ~String();

friend bool operator== (const String&amp; firststr, const String&amp; secondstr);
friend bool operator!= (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &lt; (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &gt; (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr);

};

bool operator == (const String&amp; firststr, const String&amp; secondstr);
bool operator!= (const String&amp; firststr, const String&amp; secondstr);
bool operator &lt; (const String&amp; firststr, const String&amp; secondstr);
bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr);
bool operator &gt; (const String&amp; firststr, const String&amp; secondstr);
bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr);
</code></pre>
<p>und die cpp Datei:</p>
<pre><code class="language-cpp">String::String(char* strtext)
{
	int i = 0;
	while (strtext[i] != 0)
	{
		++i;
	}
	this-&gt;Length = i;
	this-&gt;StrText = new char[i];
	for (;i&gt;0;--i)
	{
		this-&gt;StrText[i-1] = strtext[i-1];
	}
}

String::String(const String&amp; strtext)
{
	this-&gt;Length = strtext.Length;
	for (int i = 0;i&lt;strtext.Length;++i)
	{
		this-&gt;StrText[i] = strtext.StrText[i];
	}
}

String::~String()
{
	this-&gt;Length = 0;
	delete[] this-&gt;StrText;
}

int String::GetLength()
{
	return Length;
}

String&amp; String::operator=(const String&amp; strtext)
{
	if (this != &amp;strtext)
	{
		delete[] this-&gt;StrText;
		this-&gt;Length = strtext.Length;
		this-&gt;StrText = new char[Length];
		for (int i = 0;i&lt;Length;++i)
		{
			this-&gt;StrText[i] = strtext.StrText[i];
		}
	}
	return *this;
}

bool operator &gt; (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &gt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &lt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}	

	if (firststr.Length &gt; secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &gt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &lt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}

	if (firststr.Length &gt;= secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

char&amp; String::operator[](int pos)
{
	return this-&gt;StrText[pos];
}

bool operator &lt; (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &lt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &gt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}	

	if (firststr.Length &lt; secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &lt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &gt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}

	if (firststr.Length &lt;= secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator == (const String&amp; firststr, const String&amp; secondstr)
{
	if (firststr.Length != secondstr.Length)
	{
		return false;	
	}
	else
	{
		for(int i = 0; i &lt; firststr.Length;  ++i)
		{
			if (firststr.StrText[i] != 	secondstr.StrText[i])
			{
				return false;	
			}
		}
		return true;
	}
}

bool operator!= (const String&amp; firststr, const String&amp; secondstr)
{
	if (firststr.Length != secondstr.Length)
	{
		return true;	
	}
	else
	{
		for(int i = 0; i &lt; firststr.Length;  ++i)
		{
			if (firststr.StrText[i] != 	secondstr.StrText[i])
			{
				return true;	
			}
		}
		return false;
	}	
}

String String::SubStr(int posstart, int posend)
{
	if (posstart&lt;0)
	{
		posstart =  0;	
	}
	if (posend &gt;= this-&gt;Length)
	{
		posend = this-&gt;Length-1;
	}
	if (posend &lt; 0)
	{
		posend = 0;
	}

	if (posstart &gt; posend)
	{
		char* temp = new char[posstart-posend+2];
		for (int i = posend; i &lt;= posstart; ++i)
		{
			temp[posstart-i] = this-&gt;StrText[i];
		}
		temp[posstart-posend+1] = 0;
		return String(temp);	
	}
	else
	{
		char* temp = new char[posend-posstart+2];
		for (int i = posstart; i &lt;= posend;++i)
		{
			temp[i-posstart] = this-&gt;StrText[i];
		}
		temp[posend-posstart+1] = 0;
		return String(temp);	
	}
}
</code></pre>
<p>Vielen Dank schon mal im Voraus, Niko</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/121475/string-klasse</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 19:01:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/121475.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Sep 2005 15:52:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 15:52:55 GMT]]></title><description><![CDATA[<p>Hallo, ich habe zu Studienzwecken eine eigene string-Klasse geschrieben. Jetzt würde ich gerne wissen, ob man daran noch etwas verbessern kann, bzw. ob da noch Fehler drin sind.<br />
Es wäre freundlich, wenn ihr euch das mal angucken könntet und mir eine Rückmeldug geben würdet, was man noch verbessern, verändern etc. sollte.</p>
<p>Hier der header der String-Klasse:</p>
<pre><code class="language-cpp">class String
{
private:
	char* StrText;
	int Length;
public:
	int GetLength();
	String&amp; operator=(const String&amp; strtext);
	char&amp; operator[](int pos);

	String SubStr(int posstart, int posend);

	String(char* strtext = &quot;&quot;);
	String(const String&amp; strtext);	

	virtual ~String();

friend bool operator== (const String&amp; firststr, const String&amp; secondstr);
friend bool operator!= (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &lt; (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &gt; (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr);

};

bool operator == (const String&amp; firststr, const String&amp; secondstr);
bool operator!= (const String&amp; firststr, const String&amp; secondstr);
bool operator &lt; (const String&amp; firststr, const String&amp; secondstr);
bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr);
bool operator &gt; (const String&amp; firststr, const String&amp; secondstr);
bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr);
</code></pre>
<p>und die cpp Datei:</p>
<pre><code class="language-cpp">String::String(char* strtext)
{
	int i = 0;
	while (strtext[i] != 0)
	{
		++i;
	}
	this-&gt;Length = i;
	this-&gt;StrText = new char[i];
	for (;i&gt;0;--i)
	{
		this-&gt;StrText[i-1] = strtext[i-1];
	}
}

String::String(const String&amp; strtext)
{
	this-&gt;Length = strtext.Length;
	for (int i = 0;i&lt;strtext.Length;++i)
	{
		this-&gt;StrText[i] = strtext.StrText[i];
	}
}

String::~String()
{
	this-&gt;Length = 0;
	delete[] this-&gt;StrText;
}

int String::GetLength()
{
	return Length;
}

String&amp; String::operator=(const String&amp; strtext)
{
	if (this != &amp;strtext)
	{
		delete[] this-&gt;StrText;
		this-&gt;Length = strtext.Length;
		this-&gt;StrText = new char[Length];
		for (int i = 0;i&lt;Length;++i)
		{
			this-&gt;StrText[i] = strtext.StrText[i];
		}
	}
	return *this;
}

bool operator &gt; (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &gt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &lt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}	

	if (firststr.Length &gt; secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &gt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &lt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}

	if (firststr.Length &gt;= secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

char&amp; String::operator[](int pos)
{
	return this-&gt;StrText[pos];
}

bool operator &lt; (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &lt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &gt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}	

	if (firststr.Length &lt; secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr)
{
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &lt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &gt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}

	if (firststr.Length &lt;= secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator == (const String&amp; firststr, const String&amp; secondstr)
{
	if (firststr.Length != secondstr.Length)
	{
		return false;	
	}
	else
	{
		for(int i = 0; i &lt; firststr.Length;  ++i)
		{
			if (firststr.StrText[i] != 	secondstr.StrText[i])
			{
				return false;	
			}
		}
		return true;
	}
}

bool operator!= (const String&amp; firststr, const String&amp; secondstr)
{
	if (firststr.Length != secondstr.Length)
	{
		return true;	
	}
	else
	{
		for(int i = 0; i &lt; firststr.Length;  ++i)
		{
			if (firststr.StrText[i] != 	secondstr.StrText[i])
			{
				return true;	
			}
		}
		return false;
	}	
}

String String::SubStr(int posstart, int posend)
{
	if (posstart&lt;0)
	{
		posstart =  0;	
	}
	if (posend &gt;= this-&gt;Length)
	{
		posend = this-&gt;Length-1;
	}
	if (posend &lt; 0)
	{
		posend = 0;
	}

	if (posstart &gt; posend)
	{
		char* temp = new char[posstart-posend+2];
		for (int i = posend; i &lt;= posstart; ++i)
		{
			temp[posstart-i] = this-&gt;StrText[i];
		}
		temp[posstart-posend+1] = 0;
		return String(temp);	
	}
	else
	{
		char* temp = new char[posend-posstart+2];
		for (int i = posstart; i &lt;= posend;++i)
		{
			temp[i-posstart] = this-&gt;StrText[i];
		}
		temp[posend-posstart+1] = 0;
		return String(temp);	
	}
}
</code></pre>
<p>Vielen Dank schon mal im Voraus, Niko</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878711</guid><dc:creator><![CDATA[Sir Niko]]></dc:creator><pubDate>Fri, 23 Sep 2005 15:52:55 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 16:21:53 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe mir noch nicht alles angeschaut, aber mir ist folgendes aufgefallen:</p>
<p>1.) Leerstrings<br />
Willst Du keinen Standardkonstruktor für einen leeren String anbieten? Das kann gerade in Zusammenarbeit mit Templates / Standardcontainern nützlich sein.</p>
<p>2.) operator= und String(char* strtext) - Fehlerbehandlung</p>
<pre><code>delete[] this-&gt;StrText;
    this-&gt;Length = strtext.Length;
    this-&gt;StrText = new char[Length];
</code></pre>
<p>Ich würde hier auf jeden Fall überprüfen, ob das new geklappt hat, wenn es fehlschlägt, sollte der String nicht fehlerbehaftet sein, sondern z.b. ein Leerstring.</p>
<p>3.) zweiter Konstruktor<br />
Hier hast Du ein new vergessen. Du weist die Länge nur zu erstellst aber kein char-Array.</p>
<p>4.) Destruktor<br />
Warum setzt Du die Stringlänge auf 0? Das Objekt wird doch im nächsten Moment eh nicht mehr da sein....</p>
<p>Ich werde mir das weiter angucken. Das waren die ersten paar Sachen, die mir aufgefallen sind...</p>
<p>Grüße<br />
Richie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878726</guid><dc:creator><![CDATA[Richie_Gecco]]></dc:creator><pubDate>Fri, 23 Sep 2005 16:21:53 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 16:58:56 GMT]]></title><description><![CDATA[<p>Is jetzt wahrscheinlich ein wenig zu spät, aber du hättest dir viel Arbeit ersparen können wenn du z.B. operator!= mit operator== implementiert hättest:</p>
<pre><code class="language-cpp">bool operator != (const String&amp; l, const String&amp; r)
{
    return ! (l == r);
}
</code></pre>
<p>Noch besser: <a href="http://www.boost.org/libs/utility/operators.htm" rel="nofollow">Boost.Operators</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/878750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878750</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Fri, 23 Sep 2005 16:58:56 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 18:55:45 GMT]]></title><description><![CDATA[<p>Danke schonmal für die Anmerkungen!!</p>
<p>Das mit dem Punkt 3 ist mir selber gerade aufgefallen.</p>
<p>Zu dem Standardkonstruktor, welchen Vorteil hätte das gegenüber dem hier?</p>
<pre><code class="language-cpp">String(char* strtext = &quot;&quot;);
</code></pre>
<p>Zu Punkt 2, wie kann ich das überprüfen? Was passiert, wenn das new nicht geklappt hat?</p>
<p>Danke für deine Ratschläge, ich werde sie schnellstmöglich umsetzen!</p>
<p>Alle weiteren Kritikpunkte sind herzlich willkommen!</p>
<p>Niko</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878833</guid><dc:creator><![CDATA[Sir Niko]]></dc:creator><pubDate>Fri, 23 Sep 2005 18:55:45 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 18:57:04 GMT]]></title><description><![CDATA[<p>Wenn es darum geht, kann man auch so etwas schreiben:</p>
<pre><code class="language-cpp">bool operator &gt; (const String&amp; firststr, const String&amp; secondstr)
{
  return secondstr &lt; firststr;
}
</code></pre>
<p>usw.</p>
<p>Oder die etwas inperformante Methode der STL:<br />
Wir bauen alles auf less auf ;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878834</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878834</guid><dc:creator><![CDATA[Richie_Gecco]]></dc:creator><pubDate>Fri, 23 Sep 2005 18:57:04 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 19:12:21 GMT]]></title><description><![CDATA[<p>Sir Niko schrieb:</p>
<blockquote>
<p>Danke schonmal für die Anmerkungen!!</p>
<p>Das mit dem Punkt 3 ist mir selber gerade aufgefallen.</p>
<p>Zu dem Standardkonstruktor, welchen Vorteil hätte das gegenüber dem hier?</p>
<pre><code class="language-cpp">String(char* strtext = &quot;&quot;);
</code></pre>
</blockquote>
<p>Stell Dir mal vor, dass Du eine Templateklasse hast, die eine Membervariable vom template-Typen besitzt, um temporäre Werte zu speichern. Mit Deiner Implementation, musst Du der Klasse übergeben, wie sie die Membervariable für die temporären Strings konstruieren muss. Mit einem Standardkonstrukter musst Du diesen Umstand nicht machen.</p>
<blockquote>
<p>Zu Punkt 2, wie kann ich das überprüfen? Was passiert, wenn das new nicht geklappt hat?</p>
</blockquote>
<p>Eigentlich sollte new dann eine Exception werfen. Musst Du halt ein try-Block um new setzen. Viele Implementationen (gerade die Älteren) setzen den Zeiger auf NULL. Das solltest Du auf jeden Fall auch abprüfen.</p>
<p>Niko</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878842</guid><dc:creator><![CDATA[Richie_Gecco]]></dc:creator><pubDate>Fri, 23 Sep 2005 19:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 19:17:50 GMT]]></title><description><![CDATA[<p>Sorry, ganz unten sollte natürlich Richie stehen, und nicht Niko :D.</p>
<p>Grüße<br />
Richie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878845</guid><dc:creator><![CDATA[Richie_Gecco]]></dc:creator><pubDate>Fri, 23 Sep 2005 19:17:50 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 19:36:47 GMT]]></title><description><![CDATA[<p>LOOOOOOOOOOOOL <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/878848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878848</guid><dc:creator><![CDATA[sgt]]></dc:creator><pubDate>Fri, 23 Sep 2005 19:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Fri, 23 Sep 2005 20:09:28 GMT]]></title><description><![CDATA[<p>ich ändere möglichst wenig.</p>
<pre><code class="language-cpp">class String
{
private:
	char* StrText;
	int Length;
public:
	int GetLength();
	String&amp; operator=(const String&amp; strtext);
	char&amp; operator[](int pos);

	String SubStr(int posstart, int posend);

	String(char* strtext = &quot;&quot;);
	String(const String&amp; strtext);	

	virtual ~String();

friend bool operator== (const String&amp; firststr, const String&amp; secondstr);
friend bool operator!= (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &lt; (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &gt; (const String&amp; firststr, const String&amp; secondstr);
friend bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr);

};

bool operator == (const String&amp; firststr, const String&amp; secondstr);
bool operator!= (const String&amp; firststr, const String&amp; secondstr);
bool operator &lt; (const String&amp; firststr, const String&amp; secondstr);
bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr);
bool operator &gt; (const String&amp; firststr, const String&amp; secondstr);
bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr);

int myStrlen(char* str){
   int result=0;
   while(*str){
      ++str;
      ++result;
   }
   return result;
}
ist myStrcpy(char* dst,char const* src){
   while(*dst++=*scr++);//scnr
}
String::String(char* strtext)
{
	this-&gt;Length = myStrlen(strtext);
	this-&gt;StrText = new char[i];
         myStrCpy(this-&gt;StrText,strtext);
}

String::String(const String&amp; strtext)
{
	this-&gt;Length = strtext.Length;
         myStrCpy(this-&gt;StrText,strtext-&gt;strtext);
}

String::~String()
{
//	this-&gt;Length = 0;//unnötig
	delete[] this-&gt;StrText;
}

int String::GetLength()
{
	return Length;
}

String&amp; String::operator=(const String&amp; strtext)
{
	if (this == &amp;strtext)
              return *this;
	delete[] this-&gt;StrText;
	this-&gt;Length = strtext.Length;
	this-&gt;StrText = new char[Length];
         myStrCpy(this-&gt;StrText,strtext-&gt;strtext);
	return *this;
}

bool operator &gt; (const String&amp; firststr, const String&amp; secondstr)
{
         //uff! nee. zu groß. muss in wenigen zeilne gehen.
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &gt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &lt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}	

	if (firststr.Length &gt; secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator &gt;= (const String&amp; firststr, const String&amp; secondstr)
{
         //dito
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &gt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &lt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}

	if (firststr.Length &gt;= secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

char&amp; String::operator[](int pos)
{
	return this-&gt;StrText[pos];
}

bool operator &lt; (const String&amp; firststr, const String&amp; secondstr)
{
         //dito
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &lt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &gt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}	

	if (firststr.Length &lt; secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator &lt;= (const String&amp; firststr, const String&amp; secondstr)
{
         //dito
	int l;
	if (firststr.Length &lt; secondstr.Length)
	{
		l = firststr.Length;	
	}
	else
	{
		l = secondstr.Length;
	}

	for (int i = 0; i &lt; l; ++i)
	{
		if (firststr.StrText[i] &lt; secondstr.StrText[i])
		{
			return true;	
		}
		else 
		{
			if (firststr.StrText[i] &gt; secondstr.StrText[i])
			{
				return false;	
			}
		}	
	}

	if (firststr.Length &lt;= secondstr.Length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool operator == (const String&amp; firststr, const String&amp; secondstr)
{
         //dito
	if (firststr.Length != secondstr.Length)
	{
		return false;	
	}
	else
	{
		for(int i = 0; i &lt; firststr.Length;  ++i)
		{
			if (firststr.StrText[i] != 	secondstr.StrText[i])
			{
				return false;	
			}
		}
		return true;
	}
}

bool operator!= (const String&amp; firststr, const String&amp; secondstr)
{
         //dito
	if (firststr.Length != secondstr.Length)
	{
		return true;	
	}
	else
	{
		for(int i = 0; i &lt; firststr.Length;  ++i)
		{
			if (firststr.StrText[i] != 	secondstr.StrText[i])
			{
				return true;	
			}
		}
		return false;
	}	
}

private:
         String(int len){
               Length=len;
               strtext=new char[len+1];
         }
public:

String String::SubStr(int posstart, int posend)
{
         String result(posend-posstart);
         int i=0;
         for(;i&lt;posend+posstart;++i)
             result.strtext[i]=strtext[i-posstart];
         result.strtext[i]='\0';
}
</code></pre>
<p>soll keine mecker sein, sondern nur anregung. ich mach selber noch viel mehr falsch als du, und ich sage nicht, daß du meinen mist übernehmen sollst. aber vielleicht hilft's, deinen code ein wenig einfacher zu machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878858</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878858</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 23 Sep 2005 20:09:28 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Sat, 24 Sep 2005 02:47:40 GMT]]></title><description><![CDATA[<p>Ein paar weitere Methode wären vielleicht hilfreich.<br />
- zum verknüpfen zweier Strings &quot;Hallo&quot; + &quot; Welt&quot; = &quot;Hallo Welt&quot;<br />
- Typumwandlung toint, tofloat</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878929</guid><dc:creator><![CDATA[imhotep]]></dc:creator><pubDate>Sat, 24 Sep 2005 02:47:40 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Sat, 24 Sep 2005 06:19:34 GMT]]></title><description><![CDATA[<p>imhotep schrieb:</p>
<blockquote>
<p>Ein paar weitere Methode wären vielleicht hilfreich.<br />
- zum verknüpfen zweier Strings &quot;Hallo&quot; + &quot; Welt&quot; = &quot;Hallo Welt&quot;<br />
- Typumwandlung toint, tofloat</p>
</blockquote>
<p>Toint und Tofloat sind IMHO kiene gute idee, dafür sind doch stringstreams zuständig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/878937</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/878937</guid><dc:creator><![CDATA[ness]]></dc:creator><pubDate>Sat, 24 Sep 2005 06:19:34 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Sat, 24 Sep 2005 11:39:13 GMT]]></title><description><![CDATA[<p>du könntest die methoden, die den string unverändert lassen, const deklarieren, also</p>
<pre><code class="language-cpp">int GetLength() const;
</code></pre>
<p>usw.<br />
sonst könntest du diese methoden nicht anwenden, falls du mit deiner klasse einen konstanten string definierst (zB const String=&quot;Hallo&quot;).</p>
<p>auch das this-&gt; kannst du vor den objektvariablen weglassen. das macht der c++-compiler automatisch <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>
<p>was mir bei deinem code alledings ein bißchen bauchschmerzen macht, ist das new char[i] im konstruktor. wenn der string die länge 0 hat, dann allozierst du ja 0 bytes. ich bin selber noch nicht so fit in c++ und ich weiß nicht was das programm da produzieren würde, aber auf jeden fall nichts gutes <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>eine schnelle lösung dieses problems wäre, Length+1 bytes zu allozieren und das nul-byte mitzukopieren. dann könntest du intern auch die &lt;cstring&gt;-funktionen zum kopieren,vergleichen etc benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/879051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/879051</guid><dc:creator><![CDATA[Konfusius]]></dc:creator><pubDate>Sat, 24 Sep 2005 11:39:13 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Sat, 24 Sep 2005 13:32:56 GMT]]></title><description><![CDATA[<p>Konfusius schrieb:</p>
<blockquote>
<p>du könntest die methoden, die den string unverändert lassen, const deklarieren</p>
</blockquote>
<p>Sehr gute Idee. Und nicht nur bei Methoden, sondern auch bei Parametern, zB so</p>
<pre><code class="language-cpp">String(const char* strtext = &quot;&quot;);
</code></pre>
<p>Konfusius schrieb:</p>
<blockquote>
<p>was mir bei deinem code alledings ein bißchen bauchschmerzen macht, ist das new char[i] im konstruktor. wenn der string die länge 0 hat, dann allozierst du ja 0 bytes. ich bin selber noch nicht so fit in c++ und ich weiß nicht was das programm da produzieren würde, aber auf jeden fall nichts gutes <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Der Standard garantiert zumindest, dass bei Grösse 0 newtrotzdem eine gültige Adresse liefert.</p>
<p>Konfusius schrieb:</p>
<blockquote>
<p>eine schnelle lösung dieses problems wäre, Length+1 bytes zu allozieren</p>
</blockquote>
<p>Da er auf C-Strings setzt, sollte das Grundvoraussetzung sein.</p>
<p>@Sir Niko<br />
Da sowas hier schon ein paar mal gefragt wurde, solltest du mal die Forensuche benutzen. Da wirst du sicherlich noch mehr Anregungen finden.<br />
Ich habe deinen Code nur mal grob überflogen, es scheint mir aber, dass du zuviel Redundanz hast. Wenn du bestimmte Sequenzen öfters verwendest, dann lagere sowas in Funktionen aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/879109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/879109</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sat, 24 Sep 2005 13:32:56 GMT</pubDate></item><item><title><![CDATA[Reply to String-Klasse on Sat, 24 Sep 2005 13:33:17 GMT]]></title><description><![CDATA[<p>Konfusius schrieb:</p>
<blockquote>
<p>was mir bei deinem code alledings ein bißchen bauchschmerzen macht, ist das new char[i] im konstruktor. wenn der string die länge 0 hat, dann allozierst du ja 0 bytes. ich bin selber noch nicht so fit in c++ und ich weiß nicht was das programm da produzieren würde, aber auf jeden fall nichts gutes <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>das mach ich immer so. dafür erwarte ich im gegenzug aber nicht, daß delete 0; klaglos geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/879110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/879110</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 24 Sep 2005 13:33:17 GMT</pubDate></item></channel></rss>