<?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 &amp;amp; Left]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine eigene String-Klasse. Nun bin ich gerade dabei Left(n) zu implementieren.<br />
Brauche euren Rat. Was ist jetzt besser?</p>
<pre><code class="language-cpp">DT_String*	DT_String::Left(int n)
{

	string str = mpsString;
	string sub_str = str.substr(0, n);

	DT_String *ergebnis = new DT_String(sub_str.data());

	return ergebnis;
}
</code></pre>
<p>oder</p>
<pre><code class="language-cpp">DT_String	DT_String::Left(int n)
{

	string str = mpsString;
	string sub_str = str.substr(0, n);

	DT_String ergebnis = DT_String(sub_str.data());

	return ergebnis;
}
</code></pre>
<p>Merci</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/117477/string-amp-left</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 23:53:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/117477.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Aug 2005 08:52:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String &amp;amp; Left on Mon, 08 Aug 2005 08:52:05 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine eigene String-Klasse. Nun bin ich gerade dabei Left(n) zu implementieren.<br />
Brauche euren Rat. Was ist jetzt besser?</p>
<pre><code class="language-cpp">DT_String*	DT_String::Left(int n)
{

	string str = mpsString;
	string sub_str = str.substr(0, n);

	DT_String *ergebnis = new DT_String(sub_str.data());

	return ergebnis;
}
</code></pre>
<p>oder</p>
<pre><code class="language-cpp">DT_String	DT_String::Left(int n)
{

	string str = mpsString;
	string sub_str = str.substr(0, n);

	DT_String ergebnis = DT_String(sub_str.data());

	return ergebnis;
}
</code></pre>
<p>Merci</p>
]]></description><link>https://www.c-plusplus.net/forum/post/847806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/847806</guid><dc:creator><![CDATA[Tanzfreak]]></dc:creator><pubDate>Mon, 08 Aug 2005 08:52:05 GMT</pubDate></item><item><title><![CDATA[Reply to String &amp;amp; Left on Mon, 08 Aug 2005 08:59:16 GMT]]></title><description><![CDATA[<p>Zweiteres.<br />
Bei deiner ersten Lösung wäre der Aufrufer dafür verantwortlich den String freizugeben. Memoryleaks wären vorprogrammiert.<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/847815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/847815</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Mon, 08 Aug 2005 08:59:16 GMT</pubDate></item><item><title><![CDATA[Reply to String &amp;amp; Left on Mon, 08 Aug 2005 12:30:56 GMT]]></title><description><![CDATA[<p>Um unnötiges Kopieren zu vermeiden, einfach</p>
<pre><code class="language-cpp">DT_String    DT_String::Left(int n)
{    
    return DT_String(mpsString.substr(0, n).c_str());
}
</code></pre>
<p>Statt 'data()' sollte man 'c_str()' verwenden, um einen nullterminierten C-String zu erhalten ('data()' liefert nur den Zeiger auf den Buffer, der nicht unbedingt nullterminert sein muß, sonst mußt du einen Konstruktor (const char *, size_t) verwenden (Aufruf dann mit DT_String(s.data(), s.length()); ).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/847924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/847924</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Mon, 08 Aug 2005 12:30:56 GMT</pubDate></item><item><title><![CDATA[Reply to String &amp;amp; Left on Mon, 08 Aug 2005 13:07:27 GMT]]></title><description><![CDATA[<p>Th schrieb:</p>
<blockquote>
<p>Statt 'data()' sollte man 'c_str()' verwenden, um einen nullterminierten C-String zu erhalten</p>
</blockquote>
<p>Nein, besser nicht. c_str ist lediglich ein Hintertürchen und nicht für die normale Arbeit mit std::string gedacht.</p>
<p>Th schrieb:</p>
<blockquote>
<p>'data()' liefert nur den Zeiger auf den Buffer, der nicht unbedingt nullterminert sein muß</p>
</blockquote>
<p>Und wozu sollte Tanzfreak einen nullterminierten Buffer brauchen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/847957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/847957</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Mon, 08 Aug 2005 13:07:27 GMT</pubDate></item></channel></rss>