<?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[streams und eof]]></title><description><![CDATA[<p>Hallo zusammen</p>
<p>wie teste ich ein ASCII file, ob ueberhaupt etwas drin steht? Denn mein jetziger Code schreibt mir in meinen vector auf jeden Fall etwas rein, da die Schleife immer einmal durchlaufen wird. Ich moechte aber, dass der vector leer bleibt wenn das file leer ist. Wie mache ich das? Das geht doch bestimmt irgendwie mit fail, oder?</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">vector&lt;PointN&gt; loadMarkers(char* sData)
{
	FILE * markers = NULL;
	markers = fopen(sData,&quot;r&quot;);
	if (!markers)
	{
		printf(&quot;Could not open file&quot;);
		//return(-1);
	}

	vector&lt;PointN&gt; vec_markpoints;
	float float0=0.,float1=0.,float2=0.;

	while(!feof(markers))
	{
		//if(ios::fail(markers) == false)
		//{
			fscanf(markers,&quot;%f&quot;,&amp;float0);
			fscanf(markers,&quot;%f&quot;,&amp;float1);
			fscanf(markers,&quot;%f&quot;,&amp;float2);
			PointN p((double)float0,(double)float1,(double)float2);
			vec_markpoints.push_back(p);
		//}
	}

	fclose(markers);

	return vec_markpoints;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/134489/streams-und-eof</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 16:26:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/134489.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Jan 2006 13:10:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to streams und eof on Thu, 26 Jan 2006 13:10:59 GMT]]></title><description><![CDATA[<p>Hallo zusammen</p>
<p>wie teste ich ein ASCII file, ob ueberhaupt etwas drin steht? Denn mein jetziger Code schreibt mir in meinen vector auf jeden Fall etwas rein, da die Schleife immer einmal durchlaufen wird. Ich moechte aber, dass der vector leer bleibt wenn das file leer ist. Wie mache ich das? Das geht doch bestimmt irgendwie mit fail, oder?</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">vector&lt;PointN&gt; loadMarkers(char* sData)
{
	FILE * markers = NULL;
	markers = fopen(sData,&quot;r&quot;);
	if (!markers)
	{
		printf(&quot;Could not open file&quot;);
		//return(-1);
	}

	vector&lt;PointN&gt; vec_markpoints;
	float float0=0.,float1=0.,float2=0.;

	while(!feof(markers))
	{
		//if(ios::fail(markers) == false)
		//{
			fscanf(markers,&quot;%f&quot;,&amp;float0);
			fscanf(markers,&quot;%f&quot;,&amp;float1);
			fscanf(markers,&quot;%f&quot;,&amp;float2);
			PointN p((double)float0,(double)float1,(double)float2);
			vec_markpoints.push_back(p);
		//}
	}

	fclose(markers);

	return vec_markpoints;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/976922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/976922</guid><dc:creator><![CDATA[Samo]]></dc:creator><pubDate>Thu, 26 Jan 2006 13:10:59 GMT</pubDate></item><item><title><![CDATA[Reply to streams und eof on Thu, 26 Jan 2006 13:16:02 GMT]]></title><description><![CDATA[<p>setz' mal vor das PointN p(...); die Zeile &quot;if(feof(markers)) break;&quot;, damit verlässt du die Schleife vorzeitig, wenn nichts in der Datei stand.</p>
<p>(PS: Wieso nutzt du eigentlich keine fstreams?)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/976924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/976924</guid><dc:creator><![CDATA[CStoll (off)]]></dc:creator><pubDate>Thu, 26 Jan 2006 13:16:02 GMT</pubDate></item><item><title><![CDATA[Reply to streams und eof on Thu, 26 Jan 2006 13:24:32 GMT]]></title><description><![CDATA[<p>EOF wird erst gesetzt nachdem du das erste mal aus dem stream gelesen hast.<br />
Du musst den Rückgabewert von fscanf auswerten.<br />
z.B</p>
<pre><code class="language-cpp">int read_ok = 1;
    while(read_ok)
    {
       read_ok = ( fscanf(markers,&quot;%f&quot;,&amp;float0) == 1 );
       ...
    }
</code></pre>
<p>Kurt</p>
<p>EDIT: So wie CStoll sagt geht's natürlich auch. Du bekommst aber Probleme wenn in der Datei was anderes als floats ( ints ) steht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/976929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/976929</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Thu, 26 Jan 2006 13:24:32 GMT</pubDate></item></channel></rss>