<?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[Datei =&amp;gt; Byte Array]]></title><description><![CDATA[<p>Hallo, versuche mich gerade an einem Programm dass eine beliebige Datei in ein ByteArray umwandelt.</p>
<p>Das ist mein Code bis jetzt:</p>
<pre><code>int main()
{
	fstream fIn, fOut;
	fIn.open( &quot;in&quot;, ios_base::in );
	fOut.open( &quot;out.txt&quot;, ios_base::out );

	if( fIn.is_open() == false )
		return 0;

	fOut &lt;&lt; &quot;BYTE out[] = \n{&quot;;
    int CurrentByte, BytesWritten = 0;
    while( true )
    {

		if( fIn.peek() == EOF )
			break;

        CurrentByte = fIn.get();

		if( BytesWritten % 4 == 0 &amp;&amp; BytesWritten &gt;= 4 )
			fOut &lt;&lt; &quot;,\n\t&quot;;
		else
			fOut &lt;&lt; &quot;,  &quot;;

		fOut &lt;&lt; &quot;0x&quot; &lt;&lt; hex &lt;&lt; CurrentByte;

		++BytesWritten;
    }
	fOut &lt;&lt; endl &lt;&lt; &quot;};&quot;;
	fOut.close();
	fIn.close();
	cout &lt;&lt; &quot;ByteArray written to Out.txt!&quot; &lt;&lt; endl;
    cin.get();
}
</code></pre>
<p>Es funktioniert auch so weit bei kleinen Dateien, aber sobald ich dann zb eine Musikdatei in einem ByteArray haben möchte, returned fIn.peek() EOF wo eigentlich garnicht EOF sein sollte.</p>
<p>Beispiel:</p>
<pre><code>BYTE out[] = 
{
        0x49,  0x44,  0x33,  0x3,
	0x0,  0x0,  0x0,  0x0,
	0x10,  0x3d,  0x54,  0x50,
	0x45,  0x32,  0x0,  0x0,
.... (viele zeilen..)
	0xff,  0xfb,  0xa0,  0x40,
	0xd,  0x0,  0x3,  0x6f,
	0x3f,  0x42,  0x1,  0x81 
};
</code></pre>
<p>Nach 0x81 returned fIn.peek() plötzlich EOF, aber wenn ich mir die Datei in einem HexEditor anschaue sehe ich folgendes:</p>
<blockquote>
<p>42 01 81 1A E2 6F AE 68 40 2C</p>
</blockquote>
<p>Es geht praktisch nach 0x81 sehr wohl noch weiter, ich habe aber keine Ahnung warum fIn.peek() dann EOF returned. Hat hier einer eine Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/231987/datei-gt-byte-array</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 11:48:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/231987.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 18 Jan 2009 08:50:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Datei =&amp;gt; Byte Array on Sun, 18 Jan 2009 08:50:59 GMT]]></title><description><![CDATA[<p>Hallo, versuche mich gerade an einem Programm dass eine beliebige Datei in ein ByteArray umwandelt.</p>
<p>Das ist mein Code bis jetzt:</p>
<pre><code>int main()
{
	fstream fIn, fOut;
	fIn.open( &quot;in&quot;, ios_base::in );
	fOut.open( &quot;out.txt&quot;, ios_base::out );

	if( fIn.is_open() == false )
		return 0;

	fOut &lt;&lt; &quot;BYTE out[] = \n{&quot;;
    int CurrentByte, BytesWritten = 0;
    while( true )
    {

		if( fIn.peek() == EOF )
			break;

        CurrentByte = fIn.get();

		if( BytesWritten % 4 == 0 &amp;&amp; BytesWritten &gt;= 4 )
			fOut &lt;&lt; &quot;,\n\t&quot;;
		else
			fOut &lt;&lt; &quot;,  &quot;;

		fOut &lt;&lt; &quot;0x&quot; &lt;&lt; hex &lt;&lt; CurrentByte;

		++BytesWritten;
    }
	fOut &lt;&lt; endl &lt;&lt; &quot;};&quot;;
	fOut.close();
	fIn.close();
	cout &lt;&lt; &quot;ByteArray written to Out.txt!&quot; &lt;&lt; endl;
    cin.get();
}
</code></pre>
<p>Es funktioniert auch so weit bei kleinen Dateien, aber sobald ich dann zb eine Musikdatei in einem ByteArray haben möchte, returned fIn.peek() EOF wo eigentlich garnicht EOF sein sollte.</p>
<p>Beispiel:</p>
<pre><code>BYTE out[] = 
{
        0x49,  0x44,  0x33,  0x3,
	0x0,  0x0,  0x0,  0x0,
	0x10,  0x3d,  0x54,  0x50,
	0x45,  0x32,  0x0,  0x0,
.... (viele zeilen..)
	0xff,  0xfb,  0xa0,  0x40,
	0xd,  0x0,  0x3,  0x6f,
	0x3f,  0x42,  0x1,  0x81 
};
</code></pre>
<p>Nach 0x81 returned fIn.peek() plötzlich EOF, aber wenn ich mir die Datei in einem HexEditor anschaue sehe ich folgendes:</p>
<blockquote>
<p>42 01 81 1A E2 6F AE 68 40 2C</p>
</blockquote>
<p>Es geht praktisch nach 0x81 sehr wohl noch weiter, ich habe aber keine Ahnung warum fIn.peek() dann EOF returned. Hat hier einer eine Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1647504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1647504</guid><dc:creator><![CDATA[s91x]]></dc:creator><pubDate>Sun, 18 Jan 2009 08:50:59 GMT</pubDate></item><item><title><![CDATA[Reply to Datei =&amp;gt; Byte Array on Sun, 18 Jan 2009 12:22:19 GMT]]></title><description><![CDATA[<p>Das die Datei irgendwie kaputt ist, kann nicht sein, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1647588</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1647588</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 18 Jan 2009 12:22:19 GMT</pubDate></item><item><title><![CDATA[Reply to Datei =&amp;gt; Byte Array on Sun, 18 Jan 2009 12:33:36 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21360">@s91x</a></p>
<p>1. Was kommt den nach dem letzten Zeichen das noch gelesen wurde?<br />
2. ASCII 0x1a ?<br />
3. Versuch doch mal zu googeln, was der Code bedeutet<br />
4. Ich denke Du willst das file binär einlesen</p>
<p>Have fun</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1647595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1647595</guid><dc:creator><![CDATA[nobody23]]></dc:creator><pubDate>Sun, 18 Jan 2009 12:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to Datei =&amp;gt; Byte Array on Sun, 18 Jan 2009 14:46:29 GMT]]></title><description><![CDATA[<p>ja, als ich bei google gesucht hatte, hatte ich auch erfahren dass die io klassen wohl Probleme mit 0x1a haben. Habe aber nicht gefunden wie man 0x1a doch einlesen kann. Weiß das hier einer? :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1647695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1647695</guid><dc:creator><![CDATA[s91x]]></dc:creator><pubDate>Sun, 18 Jan 2009 14:46:29 GMT</pubDate></item><item><title><![CDATA[Reply to Datei =&amp;gt; Byte Array on Sun, 18 Jan 2009 14:53:00 GMT]]></title><description><![CDATA[<p>Ok, denke ich habs, wenn ich die datei so öffne</p>
<pre><code>fIn.open( &quot;in&quot;, ios_base::in | ios_base::binary );
</code></pre>
<p>Liest er auch 0x1a ein! <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1647700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1647700</guid><dc:creator><![CDATA[s91x]]></dc:creator><pubDate>Sun, 18 Jan 2009 14:53:00 GMT</pubDate></item></channel></rss>