<?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+binär+cast]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich suche den Fehler im folgenden Programm, bzw. die Lösung:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;winunix.h&gt; //_getch() für win/linux
using namespace std;

struct tdaten
{
  int i;
  char test;
  float pi;
}daten, daten2;

int main()
{
  daten.i=98;
  daten.test=65;
  daten.pi=3.14f;

  fstream f(&quot;test.txt&quot;, ios::binary|ios::out);
  f.write(&amp;daten, sizeof(daten));  //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  f.close();
  cout &lt;&lt; &quot;geschrieben...\n&quot;;
  _getch();

  fstream f2(&quot;test.txt&quot;, ios::binary|ios::in);
  f2.read(&amp;daten2, sizeof(daten2));
  f2.close();
  cout &lt;&lt; &quot;gelesen...\n&quot;;
  _getch();

  cout &lt;&lt; daten2.i &lt;&lt; &quot;\t&quot; &lt;&lt; daten.test &lt;&lt; &quot;\t&quot; &lt;&lt; daten.pi;
  _getch();
}
</code></pre>
<p>Danke schomal...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/182924/fstream-binär-cast</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 01:58:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182924.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 May 2007 17:46:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fstream+binär+cast on Wed, 30 May 2007 17:46:07 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich suche den Fehler im folgenden Programm, bzw. die Lösung:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;winunix.h&gt; //_getch() für win/linux
using namespace std;

struct tdaten
{
  int i;
  char test;
  float pi;
}daten, daten2;

int main()
{
  daten.i=98;
  daten.test=65;
  daten.pi=3.14f;

  fstream f(&quot;test.txt&quot;, ios::binary|ios::out);
  f.write(&amp;daten, sizeof(daten));  //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  f.close();
  cout &lt;&lt; &quot;geschrieben...\n&quot;;
  _getch();

  fstream f2(&quot;test.txt&quot;, ios::binary|ios::in);
  f2.read(&amp;daten2, sizeof(daten2));
  f2.close();
  cout &lt;&lt; &quot;gelesen...\n&quot;;
  _getch();

  cout &lt;&lt; daten2.i &lt;&lt; &quot;\t&quot; &lt;&lt; daten.test &lt;&lt; &quot;\t&quot; &lt;&lt; daten.pi;
  _getch();
}
</code></pre>
<p>Danke schomal...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1295436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1295436</guid><dc:creator><![CDATA[haselnusszwerg]]></dc:creator><pubDate>Wed, 30 May 2007 17:46:07 GMT</pubDate></item><item><title><![CDATA[Reply to fstream+binär+cast on Wed, 30 May 2007 17:50:59 GMT]]></title><description><![CDATA[<p>Fehlermeldung? Dort dürfte schon alles wesentliche drinstehen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1295438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1295438</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 30 May 2007 17:50:59 GMT</pubDate></item><item><title><![CDATA[Reply to fstream+binär+cast on Wed, 30 May 2007 17:53:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;

struct daten_t__
{
    unsigned int i;
    char test;
    float pi;
};

int main()
{
    daten_t daten;
    daten.i    = 98;
    daten.test = 65;
    daten.pi   = 3.14f;

    std::ofstream file_stream(&quot;test.txt&quot;, std::ios::binary | std::ios::out);
    file_stream.write(reinterpret_cast&lt;const char*&gt;(&amp;daten), sizeof(daten));
    file_stream.close();
    std::cout &lt;&lt; &quot;Daten geschrieben ...&quot; &lt;&lt; std::endl;
}
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1295440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1295440</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 30 May 2007 17:53:54 GMT</pubDate></item><item><title><![CDATA[Reply to fstream+binär+cast on Wed, 30 May 2007 18:15:40 GMT]]></title><description><![CDATA[<p>Danke, hatte es schon mit (char[*]) versucht, gab immer noch den Fehler...</p>
<p>Wie les ich das denn jetzt wieder aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1295451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1295451</guid><dc:creator><![CDATA[haselnusszwerg]]></dc:creator><pubDate>Wed, 30 May 2007 18:15:40 GMT</pubDate></item></channel></rss>