<?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[operator &amp;lt;&amp;lt; für ostream und für ofstream]]></title><description><![CDATA[<p>Hi,<br />
könnte mir jemand dafür einen Rat geben ?</p>
<p>Darf ich den operator&lt;&lt; (oder soll ich) überladen ?<br />
Es sind fast gleiche Argumente (ist das ein Fehler) ?</p>
<p>Am Bildschirm ist die Ausgabe korrekt aber in der Datei nicht.<br />
Statt 02.01.2009 schreibt er 20.10.2009 und nachfolgender setw(14)<br />
funktioniert nicht.</p>
<pre><code class="language-cpp">ostream &amp;operator&lt;&lt;(ostream &amp;ostr, const CDatum &amp;dat)
{
	ostr &lt;&lt; setw(2) &lt;&lt; setfill('0') &lt;&lt; dat.Tag &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(2) &lt;&lt; setfill('0') &lt;&lt; dat.Monat &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(4) &lt;&lt; dat.Jahr &lt;&lt; setfill(' ');
	return ostr;

}

ofstream &amp;operator&lt;&lt;(ofstream &amp;ofstr, const CDatum &amp;dat)
{
	ofstr &lt;&lt; setw(2) &lt;&lt; dat.Tag &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(2)  &lt;&lt; dat.Monat &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(4)  &lt;&lt; dat.Jahr;
	return ofstr;

}
</code></pre>
<p>Danke schön</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/251961/operator-lt-lt-für-ostream-und-für-ofstream</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 03:19:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/251961.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Oct 2009 07:34:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to operator &amp;lt;&amp;lt; für ostream und für ofstream on Tue, 13 Oct 2009 07:34:37 GMT]]></title><description><![CDATA[<p>Hi,<br />
könnte mir jemand dafür einen Rat geben ?</p>
<p>Darf ich den operator&lt;&lt; (oder soll ich) überladen ?<br />
Es sind fast gleiche Argumente (ist das ein Fehler) ?</p>
<p>Am Bildschirm ist die Ausgabe korrekt aber in der Datei nicht.<br />
Statt 02.01.2009 schreibt er 20.10.2009 und nachfolgender setw(14)<br />
funktioniert nicht.</p>
<pre><code class="language-cpp">ostream &amp;operator&lt;&lt;(ostream &amp;ostr, const CDatum &amp;dat)
{
	ostr &lt;&lt; setw(2) &lt;&lt; setfill('0') &lt;&lt; dat.Tag &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(2) &lt;&lt; setfill('0') &lt;&lt; dat.Monat &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(4) &lt;&lt; dat.Jahr &lt;&lt; setfill(' ');
	return ostr;

}

ofstream &amp;operator&lt;&lt;(ofstream &amp;ofstr, const CDatum &amp;dat)
{
	ofstr &lt;&lt; setw(2) &lt;&lt; dat.Tag &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(2)  &lt;&lt; dat.Monat &lt;&lt; &quot;.&quot;
		 &lt;&lt; setw(4)  &lt;&lt; dat.Jahr;
	return ofstr;

}
</code></pre>
<p>Danke schön</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1791759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1791759</guid><dc:creator><![CDATA[rosic]]></dc:creator><pubDate>Tue, 13 Oct 2009 07:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to operator &amp;lt;&amp;lt; für ostream und für ofstream on Tue, 13 Oct 2009 07:57:06 GMT]]></title><description><![CDATA[<p>Du darfst ihn zwar überladen, allerdings wirds dir nicht allzuviel bringen. Für alle anderen ist op&lt;&lt; nämlich nur für ostream überladen, so dass du bei der aneinanderrehung von op&lt;&lt; nur vorne eine ofstresm-Referenz hast und hinten nur einen ostream:</p>
<pre><code class="language-cpp">ofstream fout(&quot;bla.txt&quot;);
CDatum datum;
int i;

fout &lt;&lt; datum; //ok, ofstream-ausgabe
fout &lt;&lt; i      //&lt;- gibt einen ostream zurück
     &lt;&lt; datum; //&lt;- ostream-ausgabe (nicht ofstream)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1791765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1791765</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 13 Oct 2009 07:57:06 GMT</pubDate></item><item><title><![CDATA[Reply to operator &amp;lt;&amp;lt; für ostream und für ofstream on Tue, 13 Oct 2009 08:31:53 GMT]]></title><description><![CDATA[<p>Danke pumuckl,</p>
<p>dies hat mir geholfen.<br />
vladimir</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1791795</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1791795</guid><dc:creator><![CDATA[rosic]]></dc:creator><pubDate>Tue, 13 Oct 2009 08:31:53 GMT</pubDate></item></channel></rss>