<?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[stringstream &amp;lt;--&amp;gt; ostream Problem]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen Aufruf std::stringsream() &lt;&lt; &quot;test&quot; &lt;&lt; 1.<br />
Soweit so gut. Nun möchte ich aber diese Aufruf in eine Funktion übergeben welche ein stringstream erwartet. Dies funktioniert aber leider nicht weil der Ausgabeoperator von stringsream nur einen ostream zurück gibt.</p>
<p>Kann ich das irgendwie machen?</p>
<p>Nochmals formal zur Veranschaulichung:</p>
<pre><code>extern void log(std::stringstream&amp;);

log(std::stringstream() &lt;&lt; &quot;test&quot; &lt;&lt; 1);
</code></pre>
<p>Das funktioniert nicht weil versucht wird ein ostream zu übergeben; und wenn ich das vom Ausgabe-Operator erhaltene Objekt zu casten bekomme ich Fehlermeldungen über einen veralteten Cast-Operator.</p>
<p>Folgender Code würde funktionieren, aber ich möchte das stringstring-Objekt aus Design- und Performancegründen im Aufruf selber verwenden!</p>
<pre><code>extern void log(std::stringstream&amp;);

std::stringstream ss;

ss &lt;&lt; &quot;test&quot; &lt;&lt; 1;
log(ss);
</code></pre>
<p>Hat mir jemand eine Idee wie ich das Problem lösen kann.</p>
<p>Danke<br />
Rainer</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313676/stringstream-lt-gt-ostream-problem</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 03:54:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313676.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Feb 2013 12:37:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 12:37:15 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen Aufruf std::stringsream() &lt;&lt; &quot;test&quot; &lt;&lt; 1.<br />
Soweit so gut. Nun möchte ich aber diese Aufruf in eine Funktion übergeben welche ein stringstream erwartet. Dies funktioniert aber leider nicht weil der Ausgabeoperator von stringsream nur einen ostream zurück gibt.</p>
<p>Kann ich das irgendwie machen?</p>
<p>Nochmals formal zur Veranschaulichung:</p>
<pre><code>extern void log(std::stringstream&amp;);

log(std::stringstream() &lt;&lt; &quot;test&quot; &lt;&lt; 1);
</code></pre>
<p>Das funktioniert nicht weil versucht wird ein ostream zu übergeben; und wenn ich das vom Ausgabe-Operator erhaltene Objekt zu casten bekomme ich Fehlermeldungen über einen veralteten Cast-Operator.</p>
<p>Folgender Code würde funktionieren, aber ich möchte das stringstring-Objekt aus Design- und Performancegründen im Aufruf selber verwenden!</p>
<pre><code>extern void log(std::stringstream&amp;);

std::stringstream ss;

ss &lt;&lt; &quot;test&quot; &lt;&lt; 1;
log(ss);
</code></pre>
<p>Hat mir jemand eine Idee wie ich das Problem lösen kann.</p>
<p>Danke<br />
Rainer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296736</guid><dc:creator><![CDATA[ahirsra]]></dc:creator><pubDate>Thu, 07 Feb 2013 12:37:15 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:13:55 GMT]]></title><description><![CDATA[<p>Wieso kann die Funktion kein std::ostream erwarten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296747</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:13:55 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:17:03 GMT]]></title><description><![CDATA[<blockquote>
<p>Dies funktioniert aber leider nicht weil der Ausgabeoperator von stringsream nur einen ostream zurück gibt.</p>
</blockquote>
<p>Dann gib mal die Fehlermeldung an!</p>
<p>Eigentlich: Temporaere Objekte koennen nur an const-Referenzen gebunden werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296749</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:17:03 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:17:06 GMT]]></title><description><![CDATA[<p>Die ist leider in einer externe Library.</p>
<p>By the way! Wie bekomme ich eigentlich den Inhalt eines ostream in einen std::string? Das würde mir auch weiterhelfen weil die Logfunktion in der Library für Strings überladen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296750</guid><dc:creator><![CDATA[ahirsra]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:17:06 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:20:58 GMT]]></title><description><![CDATA[<blockquote>
<p>Das würde mir auch weiterhelfen weil die Logfunktion in der Library für Strings überladen ist.</p>
</blockquote>
<p>Wieso machst du aus deinem Stream nicht einen String und uebergibst ihn dann erst. Ich halte es fuer sinnfrei der Logfunktion einen Stream zu uebergeben.</p>
<pre><code>std::stringstream s;
s &lt;&lt; ... &lt;&lt; ... &lt;&lt; '\n';
log(s.str());
</code></pre>
<p>Und dann solltest due vielleicht mal das echte Problem schildern und nicht dein komischen Loesungsansatz der total verquer zu sein scheint. Also nicht: Ich moechte es so und so machen, wie kriege ich es hin. Sondern: Das ist das Problem, hier die Signatur, wie mache ich es.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296752</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:20:58 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:26:25 GMT]]></title><description><![CDATA[<p>Wie man sieht hat die Logfunktion noch mehr Parameter! Das Problem ist aber definitiv der zweite und die Sache mit stringstream!</p>
<p>test.cpp:256: error: no matching function for call to ‘log(const char*&amp;, const char [11], std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, logging::level_e)’<br />
note: candidates are: virtual void logging::ILogger::log(const char*, logging::level_e)<br />
note: virtual void logging::ILogger::log(const char*, const char*, const char*, logging::level_e)<br />
note: virtual void logging::ILogger::log(const std::stringstream&amp;, logging::level_e)<br />
note: virtual void logging::ILogger::log(const char*, const char*, const std::stringstream&amp;, logging::level_e)</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21632">@knivil</a>:<br />
Den Trick mit der Ausgabe vor dem Logaufruf ist mir schon klar, aber wie erwähnt aus bestimmten Gründen will! ich das erzeugen der Ausgabe in de Logaufruf selber hineinbringen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296754</guid><dc:creator><![CDATA[ahirsra]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:26:25 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:43:46 GMT]]></title><description><![CDATA[<p>Wieso kann das Log nicht einfach einen generellen std::ostream bekommen, was ist der Grund aus dem es auf jedem Fall nur ein stringstream sein kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296768</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:43:46 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:45:17 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6496">@dot</a>:<br />
siehe meinen Beitrag von 14:17:06 07.02.2013</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296769</guid><dc:creator><![CDATA[ahirsra]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:51:43 GMT]]></title><description><![CDATA[<p>Und was genau gibts dort zu sehen?</p>
<p>Edit: Um den &quot;Inhalt&quot; eines ostream in einen string zu bekommen, musst du eben den Inhalt des ostream aus dem ostream in einen String lesen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296774</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:51:43 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:51:09 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6496">@dot</a>: Stichwort &quot;externe Library&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296775</guid><dc:creator><![CDATA[ahirsra]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:51:09 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 13:52:23 GMT]]></title><description><![CDATA[<p>Und was genau ist jetzt das Problem mit dieser &quot;externen Library&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296778</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296778</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 07 Feb 2013 13:52:23 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 14:59:42 GMT]]></title><description><![CDATA[<p>Wenn man so will könnte man sagen:<br />
Die Frage ist wie kann ich in diese Library einen ostream ausgeben!</p>
<p>Oder: Wie mache ich aus einem ostream einen stringstream, oder wie bekomme ich die bereits in einen ostream ausgegebenen Zeichen als String?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296808</guid><dc:creator><![CDATA[ahirsra]]></dc:creator><pubDate>Thu, 07 Feb 2013 14:59:42 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 15:05:59 GMT]]></title><description><![CDATA[<p>Erstmal sollte geklaert werden, wofuer der ostream von der Bibliothek gebraucht wird. Dort werden wahrscheinlich die Fehlermeldungen hineingeschrieben. Dann gibt es noch std::ostringstream, den man ohne das Problem zu kennen, benutzt werden kann. Fuer std::ostringstream gibt es bestimmt auch str(). <a href="http://www.cplusplus.com/reference/sstream/ostringstream/" rel="nofollow">http://www.cplusplus.com/reference/sstream/ostringstream/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296814</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296814</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 07 Feb 2013 15:05:59 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 15:17:26 GMT]]></title><description><![CDATA[<p>ahirsra schrieb:</p>
<blockquote>
<p>Wenn man so will könnte man sagen:<br />
Die Frage ist wie kann ich in diese Library einen ostream ausgeben!</p>
</blockquote>
<p>Du redest von schönem Design, aber die eigentliche Quelle des unschönen Designs ist doch, dass die log-Funktion einen stringstream entgegen nimmt. Es ist nur sehr schwer vorstellbar, dass diese Funktion wirklich einen stringstream braucht und nicht eher einen ostream oder gar string. Kann man da denn nichts machen? Extern heißt ja nicht unbedingt unantastbar. Der eigentliche Fehler liegt nämlich ziemlich sicher hier.</p>
<blockquote>
<p>Oder: Wie mache ich aus einem ostream einen stringstream, oder wie bekomme ich die bereits in einen ostream ausgegebenen Zeichen als String?</p>
</blockquote>
<p>Gar nicht, ein ostream enthält keine Zeichen. Ein ostream ist eine Sammlung von Schreibeoperationen verbunden mit einer Datensenke. Wenn die Daten erst einmal darin verschwunden sind, gibt es im allgemeinen kein Zurück. Ein stringstream ist eben eine Spezialisierung, wo die Datensenke ein string ist und man natürlich an diesen String kann. Aber man kann keinen allgemeinen ostream in einen spezialisierten stringstream umwandeln. Das wäre wie den Hund zum Dackel zu machen. Nein, eine noch verrücktere Umwandlung, da ein stringstream auch gleichzeitig noch ein istream ist. Das ist wie ein beliebiges Pferd in das Maultier &quot;Hannes&quot; umwandeln zu wollen, welches bei Bauer Jansen, Landstraße 27 in 12345 Faketown auf dem Hof steht.</p>
<blockquote>
<p>Folgender Code würde funktionieren, aber ich möchte das stringstring-Objekt aus Design- und Performancegründen im Aufruf selber verwenden!</p>
</blockquote>
<p>Performance? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> Wo läge denn hier deiner Meinung nach ein Performanceunterschied? Und wie kann man performancekritische Logfunktionen haben?</p>
<p>Hier noch ein Vorschlag:</p>
<pre><code>log((ss &lt;&lt; &quot;test&quot; &lt;&lt; 1, ss));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2296816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296816</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 07 Feb 2013 15:17:26 GMT</pubDate></item><item><title><![CDATA[Reply to stringstream &amp;lt;--&amp;gt; ostream Problem on Thu, 07 Feb 2013 15:18:07 GMT]]></title><description><![CDATA[<p>ahirsra schrieb:</p>
<blockquote>
<pre><code>extern void log(std::stringstream&amp;);

log(std::stringstream() &lt;&lt; &quot;test&quot; &lt;&lt; 1);
</code></pre>
<p>Das funktioniert nicht weil versucht wird ein ostream zu übergeben;</p>
</blockquote>
<p>Versuch doch mal:</p>
<pre><code>std::stringstream foo;
foo &lt;&lt; &quot;test&quot; &lt;&lt; 1;
log(foo);
</code></pre>
<p>Edit:<br />
Tschuldigung, sehe jetzt, dass Du das schon probiert hast. Ich verstehe aber nicht, wieso Du das nicht machen willst ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296817</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Thu, 07 Feb 2013 15:18:07 GMT</pubDate></item></channel></rss>