<?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[Textdatei lesen und anzeigen]]></title><description><![CDATA[<p>Hallo,<br />
ich habe in C++ folgendes vor.<br />
Ich möchte aus einer Textdatei (text.txt) die Daten auslesen und anzeigen.<br />
Wie mache ich das?</p>
<p>Vielen Dank und Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275924/textdatei-lesen-und-anzeigen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 14:51:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275924.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Oct 2010 12:11:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 12:11:28 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe in C++ folgendes vor.<br />
Ich möchte aus einer Textdatei (text.txt) die Daten auslesen und anzeigen.<br />
Wie mache ich das?</p>
<p>Vielen Dank und Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969454</guid><dc:creator><![CDATA[bordon]]></dc:creator><pubDate>Sat, 23 Oct 2010 12:11:28 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 12:14:29 GMT]]></title><description><![CDATA[<p>welche daten?</p>
<p>es gibt ca. 20versch. arten, eine datei auszulesen - wenn du uns sagst, was drin steht, können wir dir vll den in deinem fall besten weg zeigen <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>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969455</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 23 Oct 2010 12:14:29 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 12:18:15 GMT]]></title><description><![CDATA[<p>In der Datei steht folgendes:</p>
<p>char zeichen[] = &quot;qwertz&quot;;<br />
int zahl = 1234;<br />
float f = 12.34f;<br />
string s = &quot;hallo&quot;;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969457</guid><dc:creator><![CDATA[bordon]]></dc:creator><pubDate>Sat, 23 Oct 2010 12:18:15 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 12:33:09 GMT]]></title><description><![CDATA[<p>bordon schrieb:</p>
<blockquote>
<p>In der Datei steht folgendes:</p>
<p>char zeichen[] = &quot;qwertz&quot;;<br />
int zahl = 1234;<br />
float f = 12.34f;<br />
string s = &quot;hallo&quot;;</p>
</blockquote>
<p>Binär? Oder in Textform, wie du es geschrieben hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969464</guid><dc:creator><![CDATA[......]]></dc:creator><pubDate>Sat, 23 Oct 2010 12:33:09 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 12:39:35 GMT]]></title><description><![CDATA[<p>Ich möchte es sowohl Binär, als auch als Textdatei auslesen.<br />
Darüber hinaus möchte ich die Daten in andere Variablen schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969466</guid><dc:creator><![CDATA[bordon]]></dc:creator><pubDate>Sat, 23 Oct 2010 12:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 12:54:03 GMT]]></title><description><![CDATA[<p>wer legt denn so was fest?<br />
dafür ist c++ ein wenig ungeeignet...</p>
<pre><code>//strings
zeichen = asd
//ints
zahl = 123
//floats
f = 123.f
</code></pre>
<p>würde noch relativ einfach gehen.<br />
aber schon <em>zeichen[]</em> wäre imho nicht all zu leicht zu parsen.<br />
und man bräuchte vermutlich für jeden datentyp einen container(z.B. map mit key==string, in dem der name steht).</p>
<p>es würde also auch so gehen:</p>
<pre><code>string zeichen = asd
int zahl = 123
float zahl = 123.f
string zeichen2 = hjkl
int q = 1234
</code></pre>
<p>ein möglicher ansatz wäre:</p>
<pre><code class="language-cpp">struct values
{
  template&lt;typename T&gt;
  struct container
  {
    typedef std::map&lt;std::string, T&gt; type;
  };

  container&lt;float&gt;::type floats;
  container&lt;int&gt;::type ints;
  container&lt;std::string&gt;::type strings;

  friend std::istream&amp; operator&lt;&lt; (std::istream&amp; s, values&amp; these)
  {
    std::string type;
    std::string name;
    std::string value;

    s &gt;&gt; type &gt;&gt; name &gt;&gt; skip_char&lt;'='&gt;();
    std::getline(s, value);

    if(s.bad())
      return s;

    if(type == &quot;string&quot;)
    {
      strings[name] = value;
      return s;
    }

    std::stringstream ss;
    ss &lt;&lt; value;

    if(type == &quot;int&quot;)
      ints[name] &lt;&lt; ss;
    if(type == &quot;float&quot;)
      floats[name] &lt;&lt; ss;

    /*evtl. noch failbits von ss auf s übertragen*/

    return s;
  }

private:
  template&lt;char character&gt;
  struct skip_char
  {
    friend std::istream&amp; operator&lt;&lt;(std::istream&amp; s, skip_char&amp;)
    {
      char val;
      s &gt;&gt; val;
      if(val != character)
        s.setstate(std::ios::failbit);
      return s;
    }
  };
};
</code></pre>
<p>bb</p>
<p>edit:<br />
anzuwenden:</p>
<pre><code class="language-cpp">int main()
{
  values config_values;
  std::istream config(&quot;config.txt&quot;);

  while(config_values &lt;&lt; config);

  std::cout &lt;&lt; config_values.strings[&quot;zeichen&quot;] &lt;&lt; std::endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1969473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969473</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 23 Oct 2010 12:54:03 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 13:41:28 GMT]]></title><description><![CDATA[<p>Viel besser:</p>
<pre><code>x = &quot;String&quot;
y = 10
z = 15.14141
</code></pre>
<p>Sollte vom Parsen auch nicht sonderlich schwer sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969505</guid><dc:creator><![CDATA[mmmmm]]></dc:creator><pubDate>Sat, 23 Oct 2010 13:41:28 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 13:44:13 GMT]]></title><description><![CDATA[<p>ich will keine config-datei, in der ich nicht mal sehe, welchen typ und wertebereich eine variable hat...<br />
und einfacher zu implementieren ist diese version auch keinesfalls...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969508</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 23 Oct 2010 13:44:13 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 14:10:43 GMT]]></title><description><![CDATA[<p>Hab in einem Buch nachgelesen und folgende funktionierende Lösung geschrieben:</p>
<p>char var1[10]; int var2; float var3; string var4;</p>
<p>ifstream read(&quot;Text.txt&quot;);<br />
read &gt;&gt; var1;<br />
read &gt;&gt; var2;<br />
read &gt;&gt; var3;<br />
read &gt;&gt; var4;</p>
<p>for(int i=0;i&lt;=strlen(var1);i++){<br />
cout &lt;&lt; var1[i];<br />
}<br />
cout &lt;&lt; var2 &lt;&lt; endl;<br />
cout &lt;&lt; var3 &lt;&lt; endl;<br />
cout &lt;&lt; var4 &lt;&lt; endl;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969526</guid><dc:creator><![CDATA[bordon]]></dc:creator><pubDate>Sat, 23 Oct 2010 14:10:43 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 14:16:08 GMT]]></title><description><![CDATA[<p>aber nicht mit der text-datei von oben : D</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969530</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 23 Oct 2010 14:16:08 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 14:19:43 GMT]]></title><description><![CDATA[<p>Mit der Textdatei die ich angegeben hab! Funktioniert alles</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1969534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969534</guid><dc:creator><![CDATA[bordon]]></dc:creator><pubDate>Sat, 23 Oct 2010 14:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei lesen und anzeigen on Sat, 23 Oct 2010 14:29:30 GMT]]></title><description><![CDATA[<p>troll?</p>
<pre><code>char zeichen[] = &quot;qwertz&quot;;
int zahl = 1234;
float f = 12.34f;
string s = &quot;hallo&quot;;
</code></pre>
<p>das hast du als txt-datei angegeben gehabt... das kann gar nich gehen oO</p>
<p>wenn natürlich nur</p>
<pre><code>qwerzt
1234
12.34f
hallo
</code></pre>
<p>drin steht, geht es logischerweise - allerdings hättest du dann nicht so nen crap dazu schreiben müssen, der gar nicht drin stand... -.-'</p>
<p>naja - schön, dass es jetzt funktioniert...</p>
<p>bb</p>
<p>PS:</p>
<pre><code class="language-cpp">for(int i=0;i&lt;=strlen(var1);i++){
cout &lt;&lt; var1[i];
}
</code></pre>
<p>-&gt;</p>
<pre><code class="language-cpp">cout &lt;&lt; var1;
//oder
cout.write(var1, strlen(var1));
</code></pre>
<p>oder aber besser:</p>
<pre><code class="language-cpp">//#include&lt;cstring&gt;, &lt;cstddef&gt;, &lt;algorithm&gt;, &lt;iostream&gt;

const std::size_t max_size = 10;
char var1[max_size];

read &gt;&gt; var1;

cout.write(var1, std::min(strlen(var1), max_size));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1969538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1969538</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 23 Oct 2010 14:29:30 GMT</pubDate></item></channel></rss>