<?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[Umstellung ofstream&#x2F;ifstream - MemoryStream]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte in einer Anwendung von oftream/ifstream auf MemoryStream umstellen.<br />
Dazu habe ich die beiden folgenden Methoden ...</p>
<pre><code class="language-cpp">// Schreiben (ofstream)
    ofstream outUP( (gasArbeitsVerz_Data + &quot;\\&quot; + asDateiName).c_str(), ios::binary);
    for (size_t i=0; i&lt;gvUebungPruefung.size(); i++)
    {
        outUP.write( (char*) &amp;gvUebungPruefung[i], sizeof(gvUebungPruefung[i]));
    }
    outUP.close();

// Lesen (ofstream)
    gvUebungPruefung.clear(); 
    TUebungPruefung sctUP; // Struktur
    ifstream inUP((gasArbeitsVerz_Data + &quot;\\&quot; + asDateiName).c_str(), ios::binary);
    while (inUP.read((char*)&amp;sctUP, sizeof(sctUP)))
    {
        gvUebungPruefung.push_back(sctUP);
    }
    inUP.close();
</code></pre>
<p>... wie folgt umgestellt ...</p>
<pre><code class="language-cpp">// Schreiben (MemoryStream)
    TMemoryStream* Source;
    for (size_t i=0; i&lt;gvUebungPruefung.size(); i++)
    {
        Source-&gt;WriteBuffer( (char*) &amp;gvUebungPruefung[i].iID_Protokoll, sizeof(gvUebungPruefung[i].iID_Protokoll) );
        Source-&gt;WriteBuffer( (char*) &amp;gvUebungPruefung[i].dtDatum, sizeof(gvUebungPruefung[i].dtDatum) );
        Source-&gt;WriteBuffer( (char*) &amp;gvUebungPruefung[i].cBenutzer_VN, sizeof(gvUebungPruefung[i].cBenutzer_VN));
        // usw.
    }

// Lesen (MemoryStream)
    TMemoryStream* Dest;
    while (1) // endlos; benötigt also Abbruchkriterium
    {
        if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.iID_Protokoll, sizeof(sctUP.iID_Protokoll)) ){break;}
        if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.dtDatum, sizeof(sctUP.dtDatum)) ){break;}
        if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.cBenutzer_VN, sizeof(sctUP.cBenutzer_VN)) ){break;}
    }
</code></pre>
<p>Die Methode zum Schreiben wird kompiliert, bei der Lese-Methode erscheint die Fehlermeldung:<br />
E2109 Kein zulässiger Typ</p>
<p>Die Fehlermeldung taucht in folgender Zeile auf:</p>
<pre><code class="language-cpp">if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.iID_Protokoll, sizeof(sctUP.iID_Protokoll)) ){break;}
</code></pre>
<p>Was mache ich falsch?</p>
<p>Gruß<br />
Leo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/114996/umstellung-ofstream-ifstream-memorystream</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Jul 2026 07:45:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/114996.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Jul 2005 10:46:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Sun, 10 Jul 2005 10:46:47 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte in einer Anwendung von oftream/ifstream auf MemoryStream umstellen.<br />
Dazu habe ich die beiden folgenden Methoden ...</p>
<pre><code class="language-cpp">// Schreiben (ofstream)
    ofstream outUP( (gasArbeitsVerz_Data + &quot;\\&quot; + asDateiName).c_str(), ios::binary);
    for (size_t i=0; i&lt;gvUebungPruefung.size(); i++)
    {
        outUP.write( (char*) &amp;gvUebungPruefung[i], sizeof(gvUebungPruefung[i]));
    }
    outUP.close();

// Lesen (ofstream)
    gvUebungPruefung.clear(); 
    TUebungPruefung sctUP; // Struktur
    ifstream inUP((gasArbeitsVerz_Data + &quot;\\&quot; + asDateiName).c_str(), ios::binary);
    while (inUP.read((char*)&amp;sctUP, sizeof(sctUP)))
    {
        gvUebungPruefung.push_back(sctUP);
    }
    inUP.close();
</code></pre>
<p>... wie folgt umgestellt ...</p>
<pre><code class="language-cpp">// Schreiben (MemoryStream)
    TMemoryStream* Source;
    for (size_t i=0; i&lt;gvUebungPruefung.size(); i++)
    {
        Source-&gt;WriteBuffer( (char*) &amp;gvUebungPruefung[i].iID_Protokoll, sizeof(gvUebungPruefung[i].iID_Protokoll) );
        Source-&gt;WriteBuffer( (char*) &amp;gvUebungPruefung[i].dtDatum, sizeof(gvUebungPruefung[i].dtDatum) );
        Source-&gt;WriteBuffer( (char*) &amp;gvUebungPruefung[i].cBenutzer_VN, sizeof(gvUebungPruefung[i].cBenutzer_VN));
        // usw.
    }

// Lesen (MemoryStream)
    TMemoryStream* Dest;
    while (1) // endlos; benötigt also Abbruchkriterium
    {
        if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.iID_Protokoll, sizeof(sctUP.iID_Protokoll)) ){break;}
        if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.dtDatum, sizeof(sctUP.dtDatum)) ){break;}
        if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.cBenutzer_VN, sizeof(sctUP.cBenutzer_VN)) ){break;}
    }
</code></pre>
<p>Die Methode zum Schreiben wird kompiliert, bei der Lese-Methode erscheint die Fehlermeldung:<br />
E2109 Kein zulässiger Typ</p>
<p>Die Fehlermeldung taucht in folgender Zeile auf:</p>
<pre><code class="language-cpp">if(! Dest-&gt;ReadBuffer((byte*)&amp;sctUP.iID_Protokoll, sizeof(sctUP.iID_Protokoll)) ){break;}
</code></pre>
<p>Was mache ich falsch?</p>
<p>Gruß<br />
Leo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/827685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/827685</guid><dc:creator><![CDATA[Leo Freitag]]></dc:creator><pubDate>Sun, 10 Jul 2005 10:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Mon, 11 Jul 2005 05:41:54 GMT]]></title><description><![CDATA[<p>hm ich könnte verstehen, wenn beides nicht funktioniert, da sowohl ReadBuffer() als auch WriteBuffer() einen Zeiger auf einen void*-Buffer erwarten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/828140</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/828140</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 11 Jul 2005 05:41:54 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Mon, 11 Jul 2005 09:00:25 GMT]]></title><description><![CDATA[<p>Joe_M. schrieb:</p>
<blockquote>
<p>hm ich könnte verstehen, wenn beides nicht funktioniert, da sowohl ReadBuffer() als auch WriteBuffer() einen Zeiger auf einen void*-Buffer erwarten.</p>
</blockquote>
<p>Hi,</p>
<p>hilf' mir doch bitte gerade mal auf die Sprünge. Was ist ein void*-Buffer und wie könnte eine exemplarische Zeile in Zusammenhang mit Stream aussehen.</p>
<p>Gruß<br />
Leo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/828272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/828272</guid><dc:creator><![CDATA[Leo Freitag]]></dc:creator><pubDate>Mon, 11 Jul 2005 09:00:25 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Tue, 12 Jul 2005 07:49:46 GMT]]></title><description><![CDATA[<p>Ich nehme an, er kennt den Datentyp 'byte' nicht, nimm doch in der Lesemethode auch 'char'.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/828995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/828995</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Tue, 12 Jul 2005 07:49:46 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Tue, 12 Jul 2005 18:31:41 GMT]]></title><description><![CDATA[<p>Th schrieb:</p>
<blockquote>
<p>Ich nehme an, er kennt den Datentyp 'byte' nicht, nimm doch in der Lesemethode auch 'char'.</p>
</blockquote>
<p>Hi,</p>
<p>char anstellen von byte ändert leider nichts am Ergebnis.</p>
<p>Es würde mir sicher schon 'ne Menge helfen, wenn jemand zeigen könnte, wie die ReadBuffer() bzw. WriteBuffer-Geschichte mit einem void*-Buffer beispielhaft aussehen könnte. Idealerweise mit nicht nur mit Datentyp int, sondern auf jeden Fall char[z.B. 20].</p>
<p>Gruß<br />
Leo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/829509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/829509</guid><dc:creator><![CDATA[Leo Freitag]]></dc:creator><pubDate>Tue, 12 Jul 2005 18:31:41 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Wed, 13 Jul 2005 05:26:07 GMT]]></title><description><![CDATA[<p>Hier ein kleines Beispiel:</p>
<pre><code class="language-cpp">TFileStream* myfs = NULL;
	char* myfsbuf = NULL;
	int myfsbuf_size = 1024;
	int myfsbuf_read;
	try
	{
		try
		{
			myfs = new TFileStream(asFileNameAndPath, fmOpenRead);
			myfsbuf = new char[myfsbuf_size];
			myfs-&gt;Position = 0;
			do
			{
				myfsbuf_read = myfs-&gt;Read((void*) myfsbuf, myfsbuf_size); // hier wird die char* in ein void* gecastet
				// Daten auswerten
			} while (myfsbuf_read == myfsbuf_size);
		}
		catch(...)
		{
			ShowMessage(&quot;Fehler beim Lesen der Datei.&quot;);
		}
	}
	__finally
	{
		if (myfs)
			delete myfs;
		if (myfsbuf)
			delete[] myfsbuf;
	}
</code></pre>
<p>Stör dich bitte nicht an der seltsam anmutenden Abbruchbedingung. Das war nur ein Versuch und es funktioniert. In einem richtigen Projekt würde ich sie allerdings so nicht verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/829789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/829789</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 13 Jul 2005 05:26:07 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Wed, 13 Jul 2005 07:07:53 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Wenn du Read statt ReadBuffer verwendest mußt du nicht nach void* casten. Hier geht auch das blanke char* Array. Lediglich ReadBuffer verlangt einen void-Pointer. Wobei ReadBuffer auch bloß wieder Read aufruft.</p>
<p>Ciao</p>
]]></description><link>https://www.c-plusplus.net/forum/post/829853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/829853</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 13 Jul 2005 07:07:53 GMT</pubDate></item><item><title><![CDATA[Reply to Umstellung ofstream&#x2F;ifstream - MemoryStream on Wed, 13 Jul 2005 07:23:49 GMT]]></title><description><![CDATA[<p>Funktioniert zwar, ist aber nicht dokumentiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/829865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/829865</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 13 Jul 2005 07:23:49 GMT</pubDate></item></channel></rss>