<?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[Struct - binär schreiben mit ofstream&#x2F;write]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;
typedef unsigned short int word;
typedef unsigned long int dword;

int main()
{
	char file_name[]=&quot;a.bmp&quot;;

	struct fileheader
	{
		word	bfType;
		word	bfSize;
		dword	bfReserved;
		dword	bfOffBits;
	} fheader;

		fheader.bfType		= 19778;
		fheader.bfSize		= 0;
		fheader.bfReserved	= 0;
		fheader.bfOffBits	= (sizeof(iheader)+sizeof(fheader))*8+1;

	ofstream bmp_file;
	bmp_file.open(file_name, ios_base::out | ios_base::binary);

		if(bmp_file.good())	cout &lt;&lt; &quot;Datei erstellt!&quot; &lt;&lt; endl;

		bmp_file.write(reinterpret_cast&lt;char *&gt;(&amp;fheader), sizeof(fheader));

	return 0;
}
</code></pre>
<p>Ich versuche gerade mit C++ eine Bitmap-Datei zu erstellen:</p>
<p>Mein Problem dabei ist dass er irgendwie an die 2-Byte Variablen nochmal 2-Byte dazuhängt die nur unsinn enthalten.</p>
<p>Also z.B.: FFFF 0200 | FFFF 0340 | FFFF FFFF | FFFF FFFF<br />
(FFFF ist das gewollte)</p>
<p>erkennt der nicht die Größe der Varibalen??</p>
<p>Achja und wegen WORD und DWORD: passt dass mit short int &amp; long int???</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/130590/struct-binär-schreiben-mit-ofstream-write</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 16:16:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/130590.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Dec 2005 21:02:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Struct - binär schreiben mit ofstream&#x2F;write on Sat, 24 Dec 2005 21:02:02 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;
typedef unsigned short int word;
typedef unsigned long int dword;

int main()
{
	char file_name[]=&quot;a.bmp&quot;;

	struct fileheader
	{
		word	bfType;
		word	bfSize;
		dword	bfReserved;
		dword	bfOffBits;
	} fheader;

		fheader.bfType		= 19778;
		fheader.bfSize		= 0;
		fheader.bfReserved	= 0;
		fheader.bfOffBits	= (sizeof(iheader)+sizeof(fheader))*8+1;

	ofstream bmp_file;
	bmp_file.open(file_name, ios_base::out | ios_base::binary);

		if(bmp_file.good())	cout &lt;&lt; &quot;Datei erstellt!&quot; &lt;&lt; endl;

		bmp_file.write(reinterpret_cast&lt;char *&gt;(&amp;fheader), sizeof(fheader));

	return 0;
}
</code></pre>
<p>Ich versuche gerade mit C++ eine Bitmap-Datei zu erstellen:</p>
<p>Mein Problem dabei ist dass er irgendwie an die 2-Byte Variablen nochmal 2-Byte dazuhängt die nur unsinn enthalten.</p>
<p>Also z.B.: FFFF 0200 | FFFF 0340 | FFFF FFFF | FFFF FFFF<br />
(FFFF ist das gewollte)</p>
<p>erkennt der nicht die Größe der Varibalen??</p>
<p>Achja und wegen WORD und DWORD: passt dass mit short int &amp; long int???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/949355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949355</guid><dc:creator><![CDATA[lazka]]></dc:creator><pubDate>Sat, 24 Dec 2005 21:02:02 GMT</pubDate></item><item><title><![CDATA[Reply to Struct - binär schreiben mit ofstream&#x2F;write on Sat, 24 Dec 2005 22:17:02 GMT]]></title><description><![CDATA[<p>Schreib mal die Werte einzeln nacheinander rein, ich tippe mal auf alignment.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/949379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949379</guid><dc:creator><![CDATA[..]]></dc:creator><pubDate>Sat, 24 Dec 2005 22:17:02 GMT</pubDate></item></channel></rss>