<?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[Tabelle einlesen fehlerhaft]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich bin dabei, ein Programm zu schreiben, welches eine Tabelle zeilenweise ließt und sobald ein bestimmter Wert gefunden ist, diese Zeile auf Variablen schreibt und anschließend das lesen beendet. Das sieht bisher vereinfacht so aus:</p>
<p>std::ifstream datei(&quot;Wertetabelle.txt&quot;);<br />
string zeile;</p>
<p>while (getline(datei, zeile))<br />
{<br />
stringstream zeilenpuffer(zeile);<br />
double a;<br />
double b;</p>
<p>zeilenpuffer &gt;&gt; a &gt;&gt; b;</p>
<p>if (x == a)<br />
{<br />
y = b;<br />
break;<br />
}<br />
}</p>
<p>Funktioniert auch alles, nur wenn die Tabelle nicht gefunden werden kann, möchte ich eine Meldung ausgeben, dass dies halt so ist. Kann mir jemand einen Vorschlag machen, wie das aussehen könnte? Ich bin noch ziemlicher Anfängern und habe es einfach nicht hinbekommen.</p>
<p>LG Marcel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/338709/tabelle-einlesen-fehlerhaft</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 10:15:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338709.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Jul 2016 16:48:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Tabelle einlesen fehlerhaft on Mon, 04 Jul 2016 16:49:18 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich bin dabei, ein Programm zu schreiben, welches eine Tabelle zeilenweise ließt und sobald ein bestimmter Wert gefunden ist, diese Zeile auf Variablen schreibt und anschließend das lesen beendet. Das sieht bisher vereinfacht so aus:</p>
<p>std::ifstream datei(&quot;Wertetabelle.txt&quot;);<br />
string zeile;</p>
<p>while (getline(datei, zeile))<br />
{<br />
stringstream zeilenpuffer(zeile);<br />
double a;<br />
double b;</p>
<p>zeilenpuffer &gt;&gt; a &gt;&gt; b;</p>
<p>if (x == a)<br />
{<br />
y = b;<br />
break;<br />
}<br />
}</p>
<p>Funktioniert auch alles, nur wenn die Tabelle nicht gefunden werden kann, möchte ich eine Meldung ausgeben, dass dies halt so ist. Kann mir jemand einen Vorschlag machen, wie das aussehen könnte? Ich bin noch ziemlicher Anfängern und habe es einfach nicht hinbekommen.</p>
<p>LG Marcel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501219</guid><dc:creator><![CDATA[Mars]]></dc:creator><pubDate>Mon, 04 Jul 2016 16:49:18 GMT</pubDate></item><item><title><![CDATA[Reply to Tabelle einlesen fehlerhaft on Mon, 04 Jul 2016 17:04:29 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;fstream&gt;

int main()
{
  std::ifstream tabelle(&quot;wt.txt&quot;);

  if( tabelle.bad() )
  {
    std::cout &lt;&lt; &quot;nicht gefunden&quot; &lt;&lt; std::endl;
    return 0;
  }

  double a(0.), b(0.);
  while( tabelle.good() )
  {
    tabelle &gt;&gt; a &gt;&gt; b;
    if( a == b )
    {
      std::cout &lt;&lt; &quot;gefunden&quot; &lt;&lt; std::endl;
      return 0;
    }
  };

  std::cout &lt;&lt; &quot;nicht gefunden&quot; &lt;&lt; std::endl;
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501220</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 04 Jul 2016 17:04:29 GMT</pubDate></item><item><title><![CDATA[Reply to Tabelle einlesen fehlerhaft on Tue, 05 Jul 2016 10:19:52 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;fstream&gt;

int main()
{
  std::ifstream tabelle(&quot;wt.txt&quot;);

  if( tabelle.bad() )
  {
    std::cout &lt;&lt; &quot;nicht gefunden&quot; &lt;&lt; std::endl;
    return 0;
  }

  double a(0.), b(0.);
  while( tabelle.good() )
  {
    tabelle &gt;&gt; a &gt;&gt; b;
    if( a == b )
    {
      std::cout &lt;&lt; &quot;gefunden&quot; &lt;&lt; std::endl;
      return 0;
    }
  };

  std::cout &lt;&lt; &quot;nicht gefunden&quot; &lt;&lt; std::endl;
}
</code></pre>
<p>bb</p>
</blockquote>
<p>Probiere das mal mit</p>
<p>wt.txt schrieb:</p>
<blockquote>
<p>xyz</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2501289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501289</guid><dc:creator><![CDATA[MatzeHHC]]></dc:creator><pubDate>Tue, 05 Jul 2016 10:19:52 GMT</pubDate></item><item><title><![CDATA[Reply to Tabelle einlesen fehlerhaft on Tue, 05 Jul 2016 12:26:04 GMT]]></title><description><![CDATA[<p>grml...</p>
<pre><code class="language-cpp">tabelle &gt;&gt; a &gt;&gt; b; 
    if(! tabelle )
       std::cout &lt;&lt; &quot;bad format&quot;;
    if( a == b )
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2501308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501308</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 05 Jul 2016 12:26:04 GMT</pubDate></item><item><title><![CDATA[Reply to Tabelle einlesen fehlerhaft on Tue, 05 Jul 2016 14:11:07 GMT]]></title><description><![CDATA[<p>Hallo Marcel,</p>
<p>Mars schrieb:</p>
<blockquote>
<p>Funktioniert auch alles, nur wenn die Tabelle nicht gefunden werden kann, möchte ich eine Meldung ausgeben, dass dies halt so ist. Kann mir jemand einen Vorschlag machen, wie das aussehen könnte? Ich bin noch ziemlicher Anfängern und habe es einfach nicht hinbekommen.</p>
</blockquote>
<p>Das Fehler- und EOF-Flag des Streams gibt Dir die gewünschte Information:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;

bool anforderung_erfuellt( double a, double b )
{
    return a == 1 &amp;&amp; b == 2; // oder was auch immer
}

int main()
{
    using namespace std;
    ifstream datei(&quot;Wertetabelle.txt&quot;);
    if( !datei.is_open() )
    {
        cerr &lt;&lt; &quot;Fehler beim Oeffnen der Datei&quot; &lt;&lt; endl;
        return 0;
    }
    double a, b;
    for( ; datei &gt;&gt; a &gt;&gt; b; datei.ignore( 9999, '\n' ) )
    {
        if( anforderung_erfuellt( a, b ) )
            break; // Ok
    }
    if( !datei )
    {
        if( datei.eof() )
            cout &lt;&lt; &quot;gewuenschte Werte sind nicht in der Tabelle enthalten&quot; &lt;&lt; endl;
        else
            cout &lt;&lt; &quot;Formatfehler beim Lesen(!)&quot; &lt;&lt; endl;
        return 0;
    }
    // else 
    // Ok - die Variablen a und b enthalten die gelesenen Werte

    return 0;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501331</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 05 Jul 2016 14:11:07 GMT</pubDate></item></channel></rss>