<?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[Kriege &amp;quot;basic_string::_S_create&amp;quot; ausgegeben?]]></title><description><![CDATA[<p>Folgender (absolut sinnloser) Code</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;algorithm&gt;

std::string zu_string(int x)
{
    std::string fertig;
    do
        fertig.push_back(x % 10 + '0');
    while(x /= 10);
    std::reverse(fertig.begin(), fertig.end());
    return fertig;
}

std::string operator+(const std::string&amp; b, int a)
{
    return (b + zu_string(a));
}

int main()
{
    std::string x = &quot;123&quot; + 4;
    std::cout &lt;&lt; x;
}
</code></pre>
<p>Erzeugt folgende Ausgabe:</p>
<p>Konsole schrieb:</p>
<blockquote>
<p>basic_string::_S_create</p>
</blockquote>
<p>Das er aus dem Literal &quot;123&quot; nen string macht, ist mir schon klar, es gibt ja nur ne Defintion mit nem string als Parameter. Warum gibt er mir das aber aus? Und auch wenn er das Bedürfnis hat, mir das unbedingt mitzuteilen, warum find ich im Inhalt nirgends etwas wie &quot;1234&quot;?</p>
<p>Mit</p>
<pre><code class="language-cpp">std::string x = std::string(&quot;123&quot;) + 4;
</code></pre>
<p>geht's.</p>
<p>Achja, ich hab das ganze eben auf <a href="http://ideone.com" rel="nofollow">ideone.com</a> getestet:</p>
<p><a href="http://ideone.com/iTM74" rel="nofollow">http://ideone.com/iTM74</a></p>
<p>Da ist die Ausgabe lustigerweise</p>
<p><a href="http://Ideone.com" rel="nofollow">Ideone.com</a> schrieb:</p>
<blockquote>
<p>;(</p>
</blockquote>
<p>was mir sagt, dass ich was falsch verstanden hab. Und was?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/302643/kriege-quot-basic_string-_s_create-quot-ausgegeben</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 06:50:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302643.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Apr 2012 15:57:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kriege &amp;quot;basic_string::_S_create&amp;quot; ausgegeben? on Mon, 23 Apr 2012 15:57:59 GMT]]></title><description><![CDATA[<p>Folgender (absolut sinnloser) Code</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;algorithm&gt;

std::string zu_string(int x)
{
    std::string fertig;
    do
        fertig.push_back(x % 10 + '0');
    while(x /= 10);
    std::reverse(fertig.begin(), fertig.end());
    return fertig;
}

std::string operator+(const std::string&amp; b, int a)
{
    return (b + zu_string(a));
}

int main()
{
    std::string x = &quot;123&quot; + 4;
    std::cout &lt;&lt; x;
}
</code></pre>
<p>Erzeugt folgende Ausgabe:</p>
<p>Konsole schrieb:</p>
<blockquote>
<p>basic_string::_S_create</p>
</blockquote>
<p>Das er aus dem Literal &quot;123&quot; nen string macht, ist mir schon klar, es gibt ja nur ne Defintion mit nem string als Parameter. Warum gibt er mir das aber aus? Und auch wenn er das Bedürfnis hat, mir das unbedingt mitzuteilen, warum find ich im Inhalt nirgends etwas wie &quot;1234&quot;?</p>
<p>Mit</p>
<pre><code class="language-cpp">std::string x = std::string(&quot;123&quot;) + 4;
</code></pre>
<p>geht's.</p>
<p>Achja, ich hab das ganze eben auf <a href="http://ideone.com" rel="nofollow">ideone.com</a> getestet:</p>
<p><a href="http://ideone.com/iTM74" rel="nofollow">http://ideone.com/iTM74</a></p>
<p>Da ist die Ausgabe lustigerweise</p>
<p><a href="http://Ideone.com" rel="nofollow">Ideone.com</a> schrieb:</p>
<blockquote>
<p>;(</p>
</blockquote>
<p>was mir sagt, dass ich was falsch verstanden hab. Und was?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2204951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2204951</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Mon, 23 Apr 2012 15:57:59 GMT</pubDate></item><item><title><![CDATA[Reply to Kriege &amp;quot;basic_string::_S_create&amp;quot; ausgegeben? on Mon, 23 Apr 2012 16:03:24 GMT]]></title><description><![CDATA[<p>Incocnito schrieb:</p>
<blockquote>
<p>Das er aus dem Literal &quot;123&quot; nen string macht, ist mir schon klar, es gibt ja nur ne Defintion mit nem string als Parameter.</p>
</blockquote>
<p>Denkfehler. Das Literal &quot;123&quot; ist zunächst mal ein <code>const char</code> -Array mit 4 Elementen, und &quot;123&quot;+4 ist demzufolge ein Zeiger auf die Position nach diesem Array. Da fängt halt zufälligerweise der String &quot;basic_string::_S_create&quot; an. Das ist aber undefiniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2204955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2204955</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 23 Apr 2012 16:03:24 GMT</pubDate></item><item><title><![CDATA[Reply to Kriege &amp;quot;basic_string::_S_create&amp;quot; ausgegeben? on Mon, 23 Apr 2012 16:04:47 GMT]]></title><description><![CDATA[<p>&quot;123&quot; + 4 ist irgendwelcher Mist der zufällig im Speicher hinter dem Literal &quot;123&quot; steht. Denn &quot;123&quot; in diesem Kontext zerfällt zu einem Zeiger auf die '1'.</p>
<p>edit: Zu langsam.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2204958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2204958</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 23 Apr 2012 16:04:47 GMT</pubDate></item><item><title><![CDATA[Reply to Kriege &amp;quot;basic_string::_S_create&amp;quot; ausgegeben? on Mon, 23 Apr 2012 16:09:42 GMT]]></title><description><![CDATA[<p><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="😃"
    /><br />
Oh mann. Darauf muss man aber auch erstmal kommen, wenn man vorher extra nen Operator zu rumspielen definiert.<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2204961</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2204961</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Mon, 23 Apr 2012 16:09:42 GMT</pubDate></item></channel></rss>