<?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[Frage zu cout ohne Infixschreibweise mit Manipulatoren]]></title><description><![CDATA[<p>Hallo,</p>
<p>es würde schon weiterhelfen, wenn mir jemand sagt, was aus cout &lt;&lt; 123 &lt;&lt; &quot;Hallo&quot;; ohne Infixschreibweise wird. Schreib ich nämlich nur cout.operator&lt;&lt;(&quot;Hallo&quot;), bekomm ich nur ne Adresse ausgegeben, bei operator&lt;&lt;(cout, &quot;Hallo&quot;) aber nicht, bei operator&lt;&lt;(cout, 123).operator&lt;&lt;(&quot;Hallo&quot;) bekomme ich ne Fehlermeldung (mehrdeutiger Funktionsaufruf) aber bei operator&lt;&lt;(cout, &quot;Hallo&quot;).operator&lt;&lt;(&quot;Hallo&quot;) wiederum nicht (dafür aber als Ausgabe wieder &quot;Hallo0xirgendwas&quot;). operator&lt;&lt;(cout, &quot;Hallo&quot;).operator&lt;&lt;(123) funktioniert komplett..<br />
Außerdem dachte ich dass soetwas wie operator&lt;&lt;(operator&lt;&lt;(cout, &quot;Hallo&quot;), 123) möglich wäre, da bekomme ich aber diesselbe Fehlermeldung. Ich hab versucht aus den Signaturen der Funktionen schlau zu werden, habs aber nicht hingekriegt. Und wenn ich dann versuche, sowas wie cout &lt;&lt; setw(3) ohne Infix hinzuschreiben, krieg ich gar nichts mehr hin.<br />
Wahrscheinlich überseh ich mal wieder was total offensichtliches..</p>
<p>Wäre nett, wenn da jemand Licht ins dunkle bringen würde.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/310067/frage-zu-cout-ohne-infixschreibweise-mit-manipulatoren</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 23:26:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/310067.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Nov 2012 18:52:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu cout ohne Infixschreibweise mit Manipulatoren on Fri, 02 Nov 2012 18:52:44 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>es würde schon weiterhelfen, wenn mir jemand sagt, was aus cout &lt;&lt; 123 &lt;&lt; &quot;Hallo&quot;; ohne Infixschreibweise wird. Schreib ich nämlich nur cout.operator&lt;&lt;(&quot;Hallo&quot;), bekomm ich nur ne Adresse ausgegeben, bei operator&lt;&lt;(cout, &quot;Hallo&quot;) aber nicht, bei operator&lt;&lt;(cout, 123).operator&lt;&lt;(&quot;Hallo&quot;) bekomme ich ne Fehlermeldung (mehrdeutiger Funktionsaufruf) aber bei operator&lt;&lt;(cout, &quot;Hallo&quot;).operator&lt;&lt;(&quot;Hallo&quot;) wiederum nicht (dafür aber als Ausgabe wieder &quot;Hallo0xirgendwas&quot;). operator&lt;&lt;(cout, &quot;Hallo&quot;).operator&lt;&lt;(123) funktioniert komplett..<br />
Außerdem dachte ich dass soetwas wie operator&lt;&lt;(operator&lt;&lt;(cout, &quot;Hallo&quot;), 123) möglich wäre, da bekomme ich aber diesselbe Fehlermeldung. Ich hab versucht aus den Signaturen der Funktionen schlau zu werden, habs aber nicht hingekriegt. Und wenn ich dann versuche, sowas wie cout &lt;&lt; setw(3) ohne Infix hinzuschreiben, krieg ich gar nichts mehr hin.<br />
Wahrscheinlich überseh ich mal wieder was total offensichtliches..</p>
<p>Wäre nett, wenn da jemand Licht ins dunkle bringen würde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266702</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:52:44 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu cout ohne Infixschreibweise mit Manipulatoren on Fri, 02 Nov 2012 19:01:41 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">cout.operator&lt;&lt;(&quot;Hallo&quot;)
</code></pre>
<p>Der überladene operator&lt;&lt;, der <strong>in</strong> der <code>ostream</code> Klasse definiert ist, und zu deinem Parametertyp char const [6] passt, ist</p>
<pre><code class="language-cpp">ostream&amp; operator&lt;&lt; (const void* val);
</code></pre>
<p>Klar, dass da eine Adresse ausgegeben wird <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>Aus</p>
<pre><code class="language-cpp">cout &lt;&lt; 123 &lt;&lt; &quot;Hallo&quot;;
</code></pre>
<p>Wird dank ADL irgendwie sowas wie</p>
<pre><code class="language-cpp">std::operator&lt;&lt;(std::cout.operator&lt;&lt;(123), &quot;Hallo&quot;);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2266705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266705</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:01:41 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu cout ohne Infixschreibweise mit Manipulatoren on Fri, 02 Nov 2012 19:01:03 GMT]]></title><description><![CDATA[<p>Guckst du hier: <a href="http://cplusplus.com/reference/iostream/ostream/operator%3C%3C/" rel="nofollow">http://cplusplus.com/reference/iostream/ostream/operator%3C%3C/</a><br />
siehst du, dass <code>const char*</code> -Überladungen allesamt Global sind. So schauts also richtig aus:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
int main(int argc, char** argv)
{
    operator&lt;&lt;((cout.operator&lt;&lt;(123)), &quot;Hallo&quot;);
}
</code></pre>
<p>Der innere Operator wird zuerst ausgeführt, gibt seinen Kram aus (ist eine Memberfunktion), returnt <code>cout</code> als Referenz und diese wird direkt für den äußeren benutzt, der den C-String ausgibt (ist eine Freie Funktion).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266707</guid><dc:creator><![CDATA[Der Tobi]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:01:03 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu cout ohne Infixschreibweise mit Manipulatoren on Fri, 02 Nov 2012 19:37:23 GMT]]></title><description><![CDATA[<p>Okay, danke. Soweit so gut.</p>
<p>Jetzt hab ich mir nen kleinen Manipulator gebastelt</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class Newlines
{
    int number;
public:
    Newlines(int n) : number(n) {}
    std::ostream&amp; operator()(std::ostream&amp; o) const
    {
        for(int i = 0; i &lt; number; ++i, o &lt;&lt; '\n');
        return o.flush();
    }
};

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; o,
                         const Newlines&amp; newlines)
{
    return newlines(o);
}

int main()
{
    std::operator&lt;&lt;(std::cout, Newlines(25)); //error: cannot bind 'std::ostream {aka std::basic_ostream&lt;char&gt;}' lvalue to 'std::basic_ostream&lt;char&gt;&amp;&amp;'
    std::cout.operator&lt;&lt;(Newlines(25)(std::cout));
}
</code></pre>
<p>Laut &quot;Der C++ Prorammierer&quot; (S. 377, &quot;2. Der Ausdruck cout &lt;&lt; Leerzeilen(25) wird vom Compiler in die Langform operator&lt;&lt;(cout, Leerzeilen(25)) umgewandelt. [...]&quot;) wäre ja Zeile 23 richtig, da bekomme ich aber ne Fehlermeldung. Ist ja auch klar, laut <a href="http://cplusplus.com/reference/iostream/ostream/operator%3C%3C/" rel="nofollow">http://cplusplus.com/reference/iostream/ostream/operator&lt;&lt;/</a> gibt's keinen globalen operator&lt;&lt; der Funktoren aktzeptiert.. Daher hab ich das in Zeile 24 so hingeschrieben. Das funktioniert zwar, aber mir wird dann noch eine Adresse mit ausgegeben (hinter den Leerzeilen). Warum ist das so und wie gehts richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266719</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:37:23 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu cout ohne Infixschreibweise mit Manipulatoren on Fri, 02 Nov 2012 19:50:16 GMT]]></title><description><![CDATA[<p>Wieso rufst du nicht den <code>operator&lt;&lt;</code> , den du selbst für <code>Newlines</code> geschrieben hast?</p>
<pre><code class="language-cpp">operator&lt;&lt;( std::cout, Newlines( 25 ) );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2266721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266721</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:50:16 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu cout ohne Infixschreibweise mit Manipulatoren on Fri, 02 Nov 2012 19:52:41 GMT]]></title><description><![CDATA[<p>Upps.<br />
Problem geklärt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266722</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:52:41 GMT</pubDate></item></channel></rss>