<?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[FP32 Datei einlesen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine Datei, in der binär eine N X N Höhenkarte binär als 32bit Floatingpointstream abgespeichert ist. Das 1. Float ist also die 1. Höhe der N x N Karte, das 2. Float die 2. Höhe usw.<br />
Ich will nun die gesamte Datei einlesen und hab das so probiert:</p>
<pre><code class="language-cpp">FLOAT*	heightData;
std::ifstream heightmapStream(str.c_str(), std::ios::binary);
heightmapStream.seekg(0, std::ios::end); 
UINT vertexCount = heightmapStream.tellg(); 
vertexCount /= 4;
heightmapStream.seekg(0, std::ios::beg);

// Load height data
heightData = new FLOAT[vertexCount]; 
heightmapStream.read( (char*)heightData, vertexCount*4); 
heightmapStream.close();
</code></pre>
<p>Ich öffne also die Datei, speichere in vertexCount die Anzahl Bytes, teile das durch 4 (weil jeder Float aus 4 Bytes) besteht und lese am Ende mit read() die ganze Datei in das float array.<br />
Aber genau da liegt der Hund begraben: Mein Programm hat ganz komische Anomalien und ich bin mir nicht sicher, ob dieses read da einfach so funktioniert (ob ich also einfach die Datei als char* stream einlesen kann und das dann am ende ein gültiges float array ist).</p>
<p>Mach ich das richtig und falls nein: wie ginge es richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/205210/fp32-datei-einlesen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 00:32:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/205210.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 Feb 2008 18:53:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to FP32 Datei einlesen on Mon, 11 Feb 2008 18:53:37 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine Datei, in der binär eine N X N Höhenkarte binär als 32bit Floatingpointstream abgespeichert ist. Das 1. Float ist also die 1. Höhe der N x N Karte, das 2. Float die 2. Höhe usw.<br />
Ich will nun die gesamte Datei einlesen und hab das so probiert:</p>
<pre><code class="language-cpp">FLOAT*	heightData;
std::ifstream heightmapStream(str.c_str(), std::ios::binary);
heightmapStream.seekg(0, std::ios::end); 
UINT vertexCount = heightmapStream.tellg(); 
vertexCount /= 4;
heightmapStream.seekg(0, std::ios::beg);

// Load height data
heightData = new FLOAT[vertexCount]; 
heightmapStream.read( (char*)heightData, vertexCount*4); 
heightmapStream.close();
</code></pre>
<p>Ich öffne also die Datei, speichere in vertexCount die Anzahl Bytes, teile das durch 4 (weil jeder Float aus 4 Bytes) besteht und lese am Ende mit read() die ganze Datei in das float array.<br />
Aber genau da liegt der Hund begraben: Mein Programm hat ganz komische Anomalien und ich bin mir nicht sicher, ob dieses read da einfach so funktioniert (ob ich also einfach die Datei als char* stream einlesen kann und das dann am ende ein gültiges float array ist).</p>
<p>Mach ich das richtig und falls nein: wie ginge es richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1453901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1453901</guid><dc:creator><![CDATA[floatleser]]></dc:creator><pubDate>Mon, 11 Feb 2008 18:53:37 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Mon, 11 Feb 2008 19:29:16 GMT]]></title><description><![CDATA[<p>du musst erst atof verwenden, da du Ascii einliest und nicht float.</p>
<p>mfg liggi1998</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1453924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1453924</guid><dc:creator><![CDATA[liggi1998]]></dc:creator><pubDate>Mon, 11 Feb 2008 19:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Mon, 11 Feb 2008 20:33:06 GMT]]></title><description><![CDATA[<p>atof? Ist das nicht C? Und wieso les ich die Datei als ASCII ein, wenn ich sie binär öffne? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1453970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1453970</guid><dc:creator><![CDATA[floatleser]]></dc:creator><pubDate>Mon, 11 Feb 2008 20:33:06 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Tue, 12 Feb 2008 13:48:12 GMT]]></title><description><![CDATA[<p>Weiß niemand wie das in C++ geht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454402</guid><dc:creator><![CDATA[floatleser]]></dc:creator><pubDate>Tue, 12 Feb 2008 13:48:12 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Tue, 12 Feb 2008 13:51:04 GMT]]></title><description><![CDATA[<p>Der Code sieht gut aus, deine &quot;ganz komischen Anomalien&quot; werden wohl an anderer Stelle verursacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454406</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Tue, 12 Feb 2008 13:51:04 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Tue, 12 Feb 2008 14:01:05 GMT]]></title><description><![CDATA[<p>an deiner Stelle würde ich es mal versuchen,<br />
die 4 nicht konstant in den Quellcode zu schreiben.<br />
Ersetz sie lieber mal durch sizeof(float) und guck mal, was da rauskommt.</p>
<p>Ich bin mir zwar nicht ganz sicher, aber ich meine mal gelsesen zu haben,<br />
dass ein float bereits 64 Bit hat...</p>
<p>/EDIT: sry, hab das gerade überprüft, also ignorier das eben einfach <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="😉"
    /><br />
ein float hat doch nur 4 Bytes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454419</guid><dc:creator><![CDATA[DrakoXP]]></dc:creator><pubDate>Tue, 12 Feb 2008 14:01:05 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Tue, 12 Feb 2008 14:11:09 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">FLOAT*    heightData;
std::ifstream heightmapStream(str.c_str(), std::ios::binary);
heightmapStream.seekg(0, std::ios::end);
UINT vertexCount = heightmapStream.tellg();
vertexCount /= 4;
heightmapStream.seekg(0, std::ios::beg);

// Load height data
heightData = new FLOAT[vertexCount];
heightmapStream.read( (char*)heightData, vertexCount*4);
heightmapStream.close();
</code></pre>
<p>hmpf ... naja <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>
<pre><code class="language-cpp">std::ifstream file_stream(string.c_str(), std::ios_base::binary);
if (!file_stream) throw std::invalid_argument(&quot;filename invalid&quot;);

file_stream.seekg(0, std::ios_base::end);

std::vector&lt;float&gt; heightmap(file_stream.tellg() / sizeof(float));
file_stream.read(reinterpret_cast&lt;char*&gt;(&amp;heightmap[0]), sizeof(float) * heightmap.size());
</code></pre>
<p>hmm ...</p>
<pre><code class="language-cpp">std::ifstream file_stream(string.c_str(), std::ios_base::binary);
if (!file_stream) throw std::invalid_argument(&quot;filename invalid&quot;);

std::vector&lt;float&gt; heightmap(std::istream_iterator&lt;float&gt;(file_stream), std::istream_iterator&lt;float&gt;());
</code></pre>
<p>ist aber mein favourit !;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454434</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 12 Feb 2008 14:11:09 GMT</pubDate></item><item><title><![CDATA[Reply to FP32 Datei einlesen on Tue, 12 Feb 2008 14:27:19 GMT]]></title><description><![CDATA[<p>Was genau meinst du mit &quot;hmpf naja&quot;?<br />
Dein 2. Code ist doch exakt dasselbe, nur dass du statt einem float array einen vector benutzt, oder?</p>
<p>Könnte es eigentlich ein Problem sein, dass die Floats in der Datei ein anderes Binärformat haben als es C++ benutzt? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1454457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1454457</guid><dc:creator><![CDATA[floatleser]]></dc:creator><pubDate>Tue, 12 Feb 2008 14:27:19 GMT</pubDate></item></channel></rss>