<?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 einlesen]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich möchte eine Datei einlesen, und zwar sieht so eine Datei wie folt aus:</p>
<blockquote>
<p># vtk DataFile Version 3.0<br />
Somebody's face<br />
ASCII<br />
DATASET POLYDATA<br />
POINTS 6 float<br />
0 -0.2048 -0.090616 0 -0.204 -0.090824 0 -0.2032 -0.09104<br />
0 -0.2024 -0.091256 0 -0.2016 -0.091464 0 -0.223 -0.121<br />
POLYGONS 4 16<br />
3 0 3 4<br />
3 0 1 2<br />
3 1 4 5<br />
3 1 2 6<br />
3 2 3 4</p>
</blockquote>
<p>Nach &quot;Points&quot; kommt die Anzahl der Punkte, deren Koordinaten vom Typ &quot;float&quot; sind (sind sie aber immer). Jeder Punkt besteht aus x,y,z Koordinate.<br />
Nach &quot;POLYGONS&quot; folgt die Anzahl der Polygone und dann die Größe der &quot;Zellliste&quot;, was auch immer das genau sein soll. Ich glaube das ist einfach AnzahlPolygone * 4.</p>
<p>So, ich möchte jetzt die Punkte in ein Array float Punkte [anzahl][3] speichern und die Polygone in meinetwegen in ein Array int polygone [groesse_zellliste].</p>
<p>Dafür habe ich folgenden Code geschrieben:</p>
<pre><code class="language-cpp">ifstream input(&quot;../data/test.vtk&quot;);
	string just_read = &quot; &quot;;
	int number_of_points;
	float x,y,z;			//the coordinates of one point
	int number_of_polygons;
	int size_of_cell_list;

	if(!input) cerr &lt;&lt; &quot;File not found!&quot; &lt;&lt; endl;
	while(just_read.compare(&quot;POINTS&quot;) != 0) input &gt;&gt; just_read;   //read until we read &quot;POINTS&quot;
	input &gt;&gt; number_of_points;			     	      //this is now the number of points in the file

	//we now save all the points (x,y,z) into an multidim array
	float vertices[number_of_points][3];
	for(int index = 0; input &gt;&gt; x &gt;&gt; y &gt;&gt; z; ++index) {   // &lt;-- this terminates when next z is no float
 		vertices[index][0] = x;
		vertices[index][1] = y;
		vertices[index][2] = z;
	}

	input &gt;&gt; just_read;
	cout &lt;&lt; just_read &lt;&lt; endl;
	input &gt;&gt; just_read;
	cout &lt;&lt; just_read &lt;&lt; endl;
	while(1);
</code></pre>
<p>Irgendwie scheine ich diesen &quot;&lt;&lt;&quot; bzw &quot;&gt;&gt;&quot; Operator nicht ganz zu kapieren.<br />
Die Punkte werden alle korrekt eingelsen, allerdings ist &quot;just_read&quot; in Zeile 21 und 23 jeweils das gleiche, nämlich &quot;POINTS&quot;.<br />
Das verstehe ich nicht...schiebt &quot;&gt;&gt;&quot; nicht irgendwie einen Pointer weiter?</p>
<p>Dankesehr!</p>
<p>Wimme</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/261262/datei-einlesen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 13:27:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261262.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Feb 2010 20:55:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Datei einlesen on Mon, 15 Feb 2010 20:55:37 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich möchte eine Datei einlesen, und zwar sieht so eine Datei wie folt aus:</p>
<blockquote>
<p># vtk DataFile Version 3.0<br />
Somebody's face<br />
ASCII<br />
DATASET POLYDATA<br />
POINTS 6 float<br />
0 -0.2048 -0.090616 0 -0.204 -0.090824 0 -0.2032 -0.09104<br />
0 -0.2024 -0.091256 0 -0.2016 -0.091464 0 -0.223 -0.121<br />
POLYGONS 4 16<br />
3 0 3 4<br />
3 0 1 2<br />
3 1 4 5<br />
3 1 2 6<br />
3 2 3 4</p>
</blockquote>
<p>Nach &quot;Points&quot; kommt die Anzahl der Punkte, deren Koordinaten vom Typ &quot;float&quot; sind (sind sie aber immer). Jeder Punkt besteht aus x,y,z Koordinate.<br />
Nach &quot;POLYGONS&quot; folgt die Anzahl der Polygone und dann die Größe der &quot;Zellliste&quot;, was auch immer das genau sein soll. Ich glaube das ist einfach AnzahlPolygone * 4.</p>
<p>So, ich möchte jetzt die Punkte in ein Array float Punkte [anzahl][3] speichern und die Polygone in meinetwegen in ein Array int polygone [groesse_zellliste].</p>
<p>Dafür habe ich folgenden Code geschrieben:</p>
<pre><code class="language-cpp">ifstream input(&quot;../data/test.vtk&quot;);
	string just_read = &quot; &quot;;
	int number_of_points;
	float x,y,z;			//the coordinates of one point
	int number_of_polygons;
	int size_of_cell_list;

	if(!input) cerr &lt;&lt; &quot;File not found!&quot; &lt;&lt; endl;
	while(just_read.compare(&quot;POINTS&quot;) != 0) input &gt;&gt; just_read;   //read until we read &quot;POINTS&quot;
	input &gt;&gt; number_of_points;			     	      //this is now the number of points in the file

	//we now save all the points (x,y,z) into an multidim array
	float vertices[number_of_points][3];
	for(int index = 0; input &gt;&gt; x &gt;&gt; y &gt;&gt; z; ++index) {   // &lt;-- this terminates when next z is no float
 		vertices[index][0] = x;
		vertices[index][1] = y;
		vertices[index][2] = z;
	}

	input &gt;&gt; just_read;
	cout &lt;&lt; just_read &lt;&lt; endl;
	input &gt;&gt; just_read;
	cout &lt;&lt; just_read &lt;&lt; endl;
	while(1);
</code></pre>
<p>Irgendwie scheine ich diesen &quot;&lt;&lt;&quot; bzw &quot;&gt;&gt;&quot; Operator nicht ganz zu kapieren.<br />
Die Punkte werden alle korrekt eingelsen, allerdings ist &quot;just_read&quot; in Zeile 21 und 23 jeweils das gleiche, nämlich &quot;POINTS&quot;.<br />
Das verstehe ich nicht...schiebt &quot;&gt;&gt;&quot; nicht irgendwie einen Pointer weiter?</p>
<p>Dankesehr!</p>
<p>Wimme</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1856216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1856216</guid><dc:creator><![CDATA[Wimme]]></dc:creator><pubDate>Mon, 15 Feb 2010 20:55:37 GMT</pubDate></item><item><title><![CDATA[Reply to Datei einlesen on Mon, 15 Feb 2010 20:59:54 GMT]]></title><description><![CDATA[<p>In Zeile 15 liest du so lange ein, bis der <code>istream</code> ungültig wird, also ein Fehler beim Lesen auftrat. Danach ist der <code>istream</code> ungültig und alle neuen Leseoperationen scheitern automatisch. Du musst zuerst den Fehlerstatus zurücksetzen mit<a href="http://www.cplusplus.com/reference/iostream/ios/clear/" rel="nofollow"> <code>std::istream::clear</code> </a>.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1856218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1856218</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 15 Feb 2010 20:59:54 GMT</pubDate></item><item><title><![CDATA[Reply to Datei einlesen on Mon, 15 Feb 2010 21:05:01 GMT]]></title><description><![CDATA[<p>ui, danke für die schnelle Antwort.</p>
<p>Ja, das klappt.<br />
Wann wird die Eingabe denn ungültig? Wenn das erste mal ein &quot;Nicht-Float&quot; gelesen wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1856221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1856221</guid><dc:creator><![CDATA[Wimme]]></dc:creator><pubDate>Mon, 15 Feb 2010 21:05:01 GMT</pubDate></item><item><title><![CDATA[Reply to Datei einlesen on Mon, 15 Feb 2010 21:23:18 GMT]]></title><description><![CDATA[<p>Wimme schrieb:</p>
<blockquote>
<p>Wann wird die Eingabe denn ungültig? Wenn das erste mal ein &quot;Nicht-Float&quot; gelesen wird?</p>
</blockquote>
<p>Genau. Das ist eine falsche Eingabe, wodurch der Stream ungültig wird.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1856235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1856235</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 15 Feb 2010 21:23:18 GMT</pubDate></item></channel></rss>