<?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 in Datei schlägt fehl]]></title><description><![CDATA[<p>Hi<br />
Wenn ich versuch eine strcut in eine Datei zu schreiben, schlägt die Methode immer fehl. Hier mal mein Code:</p>
<pre><code class="language-cpp">struct FHEADER
{
	byte namelen;
	byte authorlen; 
	unsigned short NumGroundTiles;
	unsigned short NumObjects;
};

std::wfstream f(L&quot;test.txt&quot;, std::ios::out | std::ios::binary);
std::wstring name(L&quot;Testname&quot;);
std::wstring author(L&quot;Testauthor&quot;);
MHEADER mh = {static_cast&lt;byte&gt;(name.size()), static_cast&lt;byte&gt;(author.size()), 1, 2};

if(!f)
	return -1;

f.write(reinterpret_cast&lt;const wchar_t *&gt;(&amp;mh), sizeof(MHEADER));

if(!f.good())
	std::wcout &lt;&lt; L&quot;Error\n&quot;;

f.close();
</code></pre>
<p>Woran liegt das? Es muss doch mit structs genau so wie mit ints usw. gehen.</p>
<p>MfG 001</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/160904/fstream-schreiben-in-datei-schlägt-fehl</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 17:25:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/160904.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Oct 2006 03:05:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 03:05:32 GMT]]></title><description><![CDATA[<p>Hi<br />
Wenn ich versuch eine strcut in eine Datei zu schreiben, schlägt die Methode immer fehl. Hier mal mein Code:</p>
<pre><code class="language-cpp">struct FHEADER
{
	byte namelen;
	byte authorlen; 
	unsigned short NumGroundTiles;
	unsigned short NumObjects;
};

std::wfstream f(L&quot;test.txt&quot;, std::ios::out | std::ios::binary);
std::wstring name(L&quot;Testname&quot;);
std::wstring author(L&quot;Testauthor&quot;);
MHEADER mh = {static_cast&lt;byte&gt;(name.size()), static_cast&lt;byte&gt;(author.size()), 1, 2};

if(!f)
	return -1;

f.write(reinterpret_cast&lt;const wchar_t *&gt;(&amp;mh), sizeof(MHEADER));

if(!f.good())
	std::wcout &lt;&lt; L&quot;Error\n&quot;;

f.close();
</code></pre>
<p>Woran liegt das? Es muss doch mit structs genau so wie mit ints usw. gehen.</p>
<p>MfG 001</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147263</guid><dc:creator><![CDATA[001]]></dc:creator><pubDate>Sun, 01 Oct 2006 03:05:32 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 08:00:36 GMT]]></title><description><![CDATA[<p>Wieso heißt es oben FHEADER und unten MHEADER?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147279</guid><dc:creator><![CDATA[906090]]></dc:creator><pubDate>Sun, 01 Oct 2006 08:00:36 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 11:04:13 GMT]]></title><description><![CDATA[<p>ups.. das ist nur ein Tippfehler aber es geht auch mit dem korrekten namen nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147330</guid><dc:creator><![CDATA[001]]></dc:creator><pubDate>Sun, 01 Oct 2006 11:04:13 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 11:34:27 GMT]]></title><description><![CDATA[<p>001 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">f.write(reinterpret_cast&lt;const wchar_t *&gt;(&amp;mh), sizeof(MHEADER));
</code></pre>
</blockquote>
<p>write(...) erwartet ein char* und nicht ein wchar_t*. Kann sein das das Problem da liegt.</p>
<pre><code class="language-cpp">[cpp]f.write(reinterpret_cast&lt;char*&gt;(&amp;mh), sizeof(MHEADER));
</code></pre>
<p>[/cpp]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147342</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147342</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 01 Oct 2006 11:34:27 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 11:38:55 GMT]]></title><description><![CDATA[<p>ich benutze std::wfstream. Genauer gesagt std::basics_festream&lt;wchar_t, std::char_traits&lt;wchar_t&gt;&gt; und deshalb will die write() methode auch ein wchar_t</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147347</guid><dc:creator><![CDATA[001]]></dc:creator><pubDate>Sun, 01 Oct 2006 11:38:55 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 11:41:44 GMT]]></title><description><![CDATA[<p>lol ich hab mal einfach anstatt wfstream fstream genommen und es scheint zu funktionieren. Aber warum geht das mit wfstream nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147348</guid><dc:creator><![CDATA[001]]></dc:creator><pubDate>Sun, 01 Oct 2006 11:41:44 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Sun, 01 Oct 2006 11:50:18 GMT]]></title><description><![CDATA[<p>001 schrieb:</p>
<blockquote>
<p>ich benutze std::wfstream. Genauer gesagt std::basics_festream&lt;wchar_t, std::char_traits&lt;wchar_t&gt;&gt; und deshalb will die write() methode auch ein wchar_t</p>
</blockquote>
<p>Achja, sry übersehen ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147354</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147354</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 01 Oct 2006 11:50:18 GMT</pubDate></item><item><title><![CDATA[Reply to fstream: Schreiben in Datei schlägt fehl on Wed, 04 Oct 2006 06:21:12 GMT]]></title><description><![CDATA[<p>001 schrieb:</p>
<blockquote>
<p>lol ich hab mal einfach anstatt wfstream fstream genommen und es scheint zu funktionieren. Aber warum geht das mit wfstream nicht?</p>
</blockquote>
<p>Möglicherweise weil wfstream::write() die Größenangabe nicht in Bytes, sondern in wchar_t's erwartet. (nur eine Idee)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148977</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 04 Oct 2006 06:21:12 GMT</pubDate></item></channel></rss>