<?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[fstream schreiben klappt nicht ganz]]></title><description><![CDATA[<p>Hi, möchte aus einem vektor der klassen archiviert, immer die variable &quot;name&quot; in eine datei schreiben. bei der Zeile, die mit &quot;output.write&quot; anfängt, stoppt der debugger, warum? habe mir nach dem debuggen die kundendaten.txt angeschaut und da werden die Namen gespeichert. allerdings nicht nur, bei 2 einträgen sieht das so aus:</p>
<pre><code>(P! name1 ÍÍÍÍÍÍÍÍÍ      ÍÍÍÍ°J! name2 ÍÍÍÍÍÍÍÍÍÍÍ      ÍÍÍÍ
</code></pre>
<p>wo ist der fehler?</p>
<pre><code>void kundendatenspeichern () {
			vector&lt;kunde&gt;:: iterator i;
			ofstream output (&quot;kundendaten.txt&quot;, ios::binary);
		for (i=kundenliste.begin();i!=kundenliste.end();i++) {
			output.write ((char*) &amp;i-&gt;name, sizeof (i-&gt;name));
		}
		output.close();
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/328209/fstream-schreiben-klappt-nicht-ganz</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 05:58:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328209.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Sep 2014 02:29:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 02:29:46 GMT]]></title><description><![CDATA[<p>Hi, möchte aus einem vektor der klassen archiviert, immer die variable &quot;name&quot; in eine datei schreiben. bei der Zeile, die mit &quot;output.write&quot; anfängt, stoppt der debugger, warum? habe mir nach dem debuggen die kundendaten.txt angeschaut und da werden die Namen gespeichert. allerdings nicht nur, bei 2 einträgen sieht das so aus:</p>
<pre><code>(P! name1 ÍÍÍÍÍÍÍÍÍ      ÍÍÍÍ°J! name2 ÍÍÍÍÍÍÍÍÍÍÍ      ÍÍÍÍ
</code></pre>
<p>wo ist der fehler?</p>
<pre><code>void kundendatenspeichern () {
			vector&lt;kunde&gt;:: iterator i;
			ofstream output (&quot;kundendaten.txt&quot;, ios::binary);
		for (i=kundenliste.begin();i!=kundenliste.end();i++) {
			output.write ((char*) &amp;i-&gt;name, sizeof (i-&gt;name));
		}
		output.close();
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2419678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419678</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 02:29:46 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 03:05:34 GMT]]></title><description><![CDATA[<pre><code>output&lt;&lt;i-&gt;name;
</code></pre>
<p>und lass das binary weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419680</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419680</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Sun, 28 Sep 2014 03:05:34 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 12:51:18 GMT]]></title><description><![CDATA[<p>Danke für die Antwort, andere Frage: ich möchte alle Membervariablen durch eine Funktion in eine Datei schreiben. Ich dachte an das folgendes: Code 2 spricht Code 1 an.</p>
<p>fehleranzeige:<br />
error C2248: &quot;std::basic_ios&lt;_Elem,_Traits&gt;::basic_ios&quot;: Kein Zugriff auf private Member, dessen Deklaration in der std::basic_ios&lt;_Elem,_Traits&gt;-Klasse erfolgte.</p>
<p>Werde draus nicht schlau..</p>
<p>Klasse die sich im Vektor der Klasse (2ter Code) befindet:</p>
<pre><code>void schreibedaten (ofstream x) {
		cout &lt;&lt;&quot;Kundendaten von Kunden ID: &quot; &lt;&lt; id &lt;&lt; &quot; werden gesichert.&quot;;
		x &lt;&lt; &quot;Name: &quot; &lt;&lt; name &lt;&lt; endl;
		x &lt;&lt; &quot;Kontostand: &quot; &lt;&lt; cash &lt;&lt; endl &lt;&lt; endl;
	}
</code></pre>
<p>Klasse die den Vektor beinhaltet und anspricht:</p>
<pre><code>void kundendatenspeichern () {
				vector&lt;kunde&gt;:: iterator i;
				ofstream output (&quot;kundendaten.txt&quot;);
		for (i=kundenliste.begin();i!=kundenliste.end();i++) {
			i-&gt;schreibedaten(output);
		}
		output.close();
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2419707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419707</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 12:51:18 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 12:53:47 GMT]]></title><description><![CDATA[<p>Ach ja Funktionen sind beide in Public und wenn ich die Membervariablen testweise in Public verschiebe ändert sich die Fehlermeldung nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419709</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 12:53:47 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 12:56:11 GMT]]></title><description><![CDATA[<p>Ah noch was, bin an gängigeren Vorgehensweisen sehr interessiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419710</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 12:56:11 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 12:56:28 GMT]]></title><description><![CDATA[<p>Du versuchst, deinen <code>ofstream</code> zu kopieren. Das geht nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419711</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Sun, 28 Sep 2014 12:56:28 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 13:02:26 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>fehleranzeige:<br />
error C2248: &quot;std::basic_ios&lt;_Elem,_Traits&gt;::basic_ios&quot;: Kein Zugriff auf private Member, dessen Deklaration in der std::basic_ios&lt;_Elem,_Traits&gt;-Klasse erfolgte.</p>
</blockquote>
<p>Das ist nicht die vollständige Fehlermeldung.<br />
Wie schon gesagt, der Fehler ist, dass du versuchst den Stream zu kopieren.<br />
Um Kopien zu verhindern, wurde vor C++11 die entsprechende Memberfunktion privat deklariert.<br />
Der Compiler sagt dir nun, dass du eine private Funktion nicht aufrufen darfst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419712</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 28 Sep 2014 13:02:26 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 13:24:03 GMT]]></title><description><![CDATA[<p>An Leute mit dem selben Problem:<br />
Die Antwort sind Zeiger.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419714</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 13:24:03 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 13:33:03 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>An Leute mit dem selben Problem:<br />
Die Antwort sind Zeiger.</p>
</blockquote>
<p>Eher micht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419715</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419715</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 28 Sep 2014 13:33:03 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 13:37:55 GMT]]></title><description><![CDATA[<p>was dann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419717</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 13:37:55 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 13:39:41 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>An Leute mit dem selben Problem:<br />
Die Antwort sind Zeiger.</p>
</blockquote>
<p>Nimm lieber Referenzen.</p>
<pre><code>class xyz
{
    public:
    ostream &amp;toStream( ostream &amp;str ) const
    {
        return str &lt;&lt; member1  &lt;&lt; member2; // etc
    }
};

inline ostream &amp;operator &lt;&lt; ( ostream &amp;str, const xyz &amp;obj )
{
    return obj.toStream( str );
}

...

    xyz obx = &lt;was auch immer&gt;

    ofstream datei( &quot;datei.txt&quot; );

    datei &lt;&lt; obj;
</code></pre>
<p>Nur ein Codefragement, Tippfehler bitte selber korigieren. Man könnte den operator auch als friend deklarieren, oder getterfunktionen aufrufen und damit toStream ersetzen. friend benutze ich aber nur, wenn's unbedingt sein muß.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419718</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Sun, 28 Sep 2014 13:39:41 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 14:43:23 GMT]]></title><description><![CDATA[<p>Warum lieber referenzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419721</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 14:43:23 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 14:53:27 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>Warum lieber referenzen?</p>
</blockquote>
<p>Hausaufgabe: Schreibe das Beispiel von mir um, indem Du statt Referenzen Zeiger benutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419722</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Sun, 28 Sep 2014 14:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 15:15:35 GMT]]></title><description><![CDATA[<p>Ich meine bezogen auf mein Beispiel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419723</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 15:15:35 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 15:21:10 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>Ich meine bezogen auf mein Beispiel</p>
</blockquote>
<p>Das gilt auch bezogen für dein Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419724</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 28 Sep 2014 15:21:10 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 15:23:14 GMT]]></title><description><![CDATA[<p>Und wo ist hier das Problem?</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

int addition () {
	int hallo = 1;
	int tschuss = 2;
	return hallo &lt;&lt; tschuss;
}

int main () {

	int zahl1 = 0,
	int zahl2 = 0;
	zahl1, zahl2 = addition ();

	cout &lt;&lt; zahl1 &lt;&lt; endl &lt;&lt; zahl2 &lt;&lt; endl;

	system (&quot;PAUSE&quot;);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2419725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419725</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 15:23:14 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 15:27:01 GMT]]></title><description><![CDATA[<p>angenommen das , hinter zahl 1 wäre ein semikolon. statt der ausgabe 1,2 kommt 0,4</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419726</guid><dc:creator><![CDATA[AnfängerPlusPlus]]></dc:creator><pubDate>Sun, 28 Sep 2014 15:27:01 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 15:40:56 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>angenommen das , hinter zahl 1 wäre ein semikolon. statt der ausgabe 1,2 kommt 0,4</p>
</blockquote>
<p>Warum statt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419729</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 28 Sep 2014 15:40:56 GMT</pubDate></item><item><title><![CDATA[Reply to fstream schreiben klappt nicht ganz on Sun, 28 Sep 2014 16:14:50 GMT]]></title><description><![CDATA[<p>AnfängerPlusPlus schrieb:</p>
<blockquote>
<p>angenommen das , hinter zahl 1 wäre ein semikolon. statt der ausgabe 1,2 kommt 0,4</p>
</blockquote>
<p>lies bitte ein Grundlagenbuch und stochere hier nicht rum.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2419732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2419732</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Sun, 28 Sep 2014 16:14:50 GMT</pubDate></item></channel></rss>