<?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[Zeile für Zeile aus Textdatei auslesen]]></title><description><![CDATA[<p>Hi,<br />
ich versuche ein Programm zu schreiben, welches Wörter der Reihe nach bearbeitet, dafür will ich eine Textdatei haben, in welcher Wörtern aufgelistet sind, die jeweils eine Zeile besetzen. Ich will dann über das Programm sagen können, in welcher Zeile sich welches Wort befindet und natürlich möchte ich auch die Wörter auslesen können. Nun hab ich aber keine Ahnung wie ich anfangen soll und wäre über eine Antwort sehr erfreut..</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/190758/zeile-für-zeile-aus-textdatei-auslesen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 19:59:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/190758.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Aug 2007 15:01:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 15:01:53 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich versuche ein Programm zu schreiben, welches Wörter der Reihe nach bearbeitet, dafür will ich eine Textdatei haben, in welcher Wörtern aufgelistet sind, die jeweils eine Zeile besetzen. Ich will dann über das Programm sagen können, in welcher Zeile sich welches Wort befindet und natürlich möchte ich auch die Wörter auslesen können. Nun hab ich aber keine Ahnung wie ich anfangen soll und wäre über eine Antwort sehr erfreut..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352386</guid><dc:creator><![CDATA[KKaiser]]></dc:creator><pubDate>Sun, 26 Aug 2007 15:01:53 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 15:03:59 GMT]]></title><description><![CDATA[<p>Naja, du könntest von einem filestream aus mit std::getline() alle Zeilen in einen vector lesen, und diesen dann nach dem Wort durchsuchen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352388</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sun, 26 Aug 2007 15:03:59 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 15:16:11 GMT]]></title><description><![CDATA[<p>Versuche es mal damit...</p>
<pre><code class="language-cpp">ifstream dat_ein;
dat_ein.open(DATEINAME.c_str(), ios_base::in);
while(!dat_ein.eof())
{
     dat_ein &gt;&gt; EINGABE;
     cout &lt;&lt; EINGABE &lt;&lt; endl;
}
dat_ein.close();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1352394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352394</guid><dc:creator><![CDATA[Ivo]]></dc:creator><pubDate>Sun, 26 Aug 2007 15:16:11 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 15:42:05 GMT]]></title><description><![CDATA[<p>wenn du damit noch weiterarbeiten und spaeter noch wissen willst, in welcher zeile welches wort steht, benutz z.B. nen vector:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

// ...

vector&lt; string &gt; zeilen;

ifstream fin;
fin.open( &quot;DATEINAME&quot;, ios_base::in );
if( !fin )
  cout &lt;&lt; &quot;Datei konnte nicht geoeffnet werden!&quot; &lt;&lt; endl;
else
{
  while( !fin.eof() )
  {
    char cZeile[ 256 ];
    fin.getline( czeile, 256 );
    string sZeile( cZeile );
    zeilen.push_back( sZeile );
  }
}
/ ***
</code></pre>
<p>(ungetestet!)</p>
<p>wenn du nun den vector nicht aenderst (elemente einfuegen/loeschen), ist position im vector gleich der zeile in der datei.<br />
also das 5. element im vector (<a href="http://zeilen.at" rel="nofollow">zeilen.at</a>( 4 )) steht auch in der 5. zeile der datei (sofern man bei 1 anfaengt die zeilen zu zaehlen, nicht bei 0).</p>
<p>mfg,<br />
julian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352406</guid><dc:creator><![CDATA[Julian__]]></dc:creator><pubDate>Sun, 26 Aug 2007 15:42:05 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 15:37:11 GMT]]></title><description><![CDATA[<p>Julian__ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

// ...

vector&lt; string &gt; zeilen;

ifstream fin;
fin.open( &quot;DATEINAME&quot;, ios_base::in );
if( !fin )
  cout &lt;&lt; &quot;Datei konnte nicht geoeffnet werden!&quot; &lt;&lt; endl;
else
{
  while( !fin.eof() )
  {
    char cZeile[ 256 ];
    fin.getline( czeile, 256 );
    string sZeile( cZeile );
    zeilen.push_back( sZeile );
  }
}
/ ***
</code></pre>
</blockquote>
<p>Wieso immer der Umweg über char-arrays? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;

std::vector&lt;std::string&gt; zeilen;

std::ifstream fin(&quot;DATEINAME&quot;, std::ios::in);
if(!fin)
{
	std::cout &lt;&lt; &quot;Datei konnte nicht geoeffnet werden!&quot; &lt;&lt; std::endl;
}
else
{
	std::string zeile;
	while(!fin.eof())
	{
		std::getline(fin, zeile);
		zeilen.push_back(zeile);
	}
}
</code></pre>
<p>(Ebenfalls ungetestet <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    />)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352408</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sun, 26 Aug 2007 15:37:11 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 15:41:20 GMT]]></title><description><![CDATA[<p>stimmt, da ist ja noch die globale std::getline-funktion ...<br />
danke fuer die korrektur!</p>
<p>mfg,<br />
julian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352411</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352411</guid><dc:creator><![CDATA[Julian__]]></dc:creator><pubDate>Sun, 26 Aug 2007 15:41:20 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 16:38:04 GMT]]></title><description><![CDATA[<p>Danke für die schnelle Antwort, nur leider hab ich jetzt ein neues Problem da mein Compiler 4 Warnungen und einen Fehler angibt.</p>
<p>warning C4786: 'std::reverse_iterator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const *,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const &amp;,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const *,int&gt;' : identifier was truncated to '255' characters in the debug information</p>
<p>warning C4786: 'std::reverse_iterator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; *,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp;,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; *,int&gt;' : identifier was truncated to '255' characters in the debug information</p>
<p>c:\programme\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::allocator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt; &gt;:: vector&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::allocator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt; &gt;' : identifier was truncated to '255' characters in the debug information</p>
<p>c:\programme\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::allocator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt; &gt;::<br />
~vector&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::allocator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt; &gt;' : identifier was truncated to '255' characters in the debug information</p>
<p>error C2065: 'Lese_Liste' : undeclared identifier</p>
<p>Mein Quelltext</p>
<pre><code>vector&lt;string&gt; zeilen;

	ifstream OeffneWordlist(DateiName, ios::in);

	if (OeffneWordlist != NULL)
	{
		string zeile; 

		while(!OeffneWordlist.eof()) 
		{ 
			getline(OeffneWordlist, zeile); 
			zeilen.push_back(zeile); 
		}

	}
</code></pre>
<p>Hab leider keine Ahnung was ich falsch gemacht hab, wäre schön wenn mir dadrauf auch jemand eine Antwort geben könnte</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352432</guid><dc:creator><![CDATA[KKaiser]]></dc:creator><pubDate>Sun, 26 Aug 2007 16:38:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 16:45:45 GMT]]></title><description><![CDATA[<p>An dem Stück sieht soweit ich es sehe alles richtig aus, vielleicht postest du noch etwas mehr code?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352436</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sun, 26 Aug 2007 16:45:45 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 17:50:09 GMT]]></title><description><![CDATA[<p>Die komplette Funktion:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;conio.h&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

#include &quot;Funktionen.h&quot;

using namespace std;

int UeberpruefeWordlist()
{

	system (&quot;cls&quot;);
	cout &lt;&lt; &quot;Bitte geben Sie den Dateinamen der Wordlist an: &quot;;

	char DateiName[1024];
	char PufferC;
	int PufferI;

	for (int Eingabe = 0; Eingabe &lt; 1024; Eingabe++)

	{
		PufferC = _getch();

		PufferI = static_cast&lt;int&gt; (PufferC);

		if (PufferI == 28)
		{
			DateiName[Eingabe] = '\0';
			Eingabe = 1024;
		}

		else
		{
			cout &lt;&lt; PufferC;

			DateiName[Eingabe] = PufferC;
		}		 
	}

	vector&lt;string&gt; zeilen;

	ifstream OeffneWordlist(DateiName, ios::in);

	if (OeffneWordlist != NULL)
	{
		string zeile; 

		while(!OeffneWordlist.eof()) 
		{ 
			getline(OeffneWordlist, zeile); 
			zeilen.push_back(zeile); 
		}

	}

	else
		MessageBox(NULL, &quot;Wordlist nicht vohanden, bitte geben Sie einen anderen Namen an&quot;, &quot;Fehler&quot;, MB_OK | MB_ICONERROR);

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1352493</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352493</guid><dc:creator><![CDATA[KKaiser]]></dc:creator><pubDate>Sun, 26 Aug 2007 17:50:09 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 18:47:30 GMT]]></title><description><![CDATA[<p>ich hab es mal eben probiert und dieses testprogramm funktioniert bei mir problemlos:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
 // #include &lt;conio.h&gt; /*  brauch ich nicht :) */
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

// #include &quot;Funktionen.h&quot; /* hab ich nicht :) */

using namespace std;

vector&lt; string &gt; UeberpruefeWordlist()
{
	string dateiname;
    system (&quot;cls&quot;);
    cout &lt;&lt; &quot;Bitte geben Sie den Dateinamen der Wordlist an: &quot;;
	cin &gt;&gt; dateiname;
	cout &lt;&lt; endl;

    vector&lt;string&gt; zeilen;
    ifstream OeffneWordlist(dateiname.c_str(), ios::in);
    if (OeffneWordlist != NULL)
    {
        string zeile;
        while(!OeffneWordlist.eof())
        {
            getline(OeffneWordlist, zeile);
            zeilen.push_back(zeile);
        }
    }
	else
		MessageBox(NULL, &quot;Wordlist nicht vohanden, bitte geben Sie einen anderen Namen an&quot;, &quot;Fehler&quot;, MB_OK | MB_ICONERROR);

    return zeilen;
}

int main()
{
	vector&lt; string &gt; zeilen = UeberpruefeWordlist();
	bool leer = true;
	for( int i = 0; i &lt; zeilen.size(); i++ )
		if( zeilen.at( i ) != &quot;&quot; ) // =&gt; mindestens in einer zeile steht etwas, also keine komplett leere datei -&gt; ergebnisse ausgeben und schleife beenden
		{
			leer = false;
			for( int j = 0; j &lt; zeilen.size(); j++ )
			{
				cout &lt;&lt; &quot;zeile &quot; &lt;&lt; j + 1;

				// nur fuer die einrueckung der ausgabe
				if( j &gt;= 99 )
					cout &lt;&lt; &quot;\t&quot;;
				else if( j &gt;= 9 )
					cout &lt;&lt; &quot;\t\t&quot;;
				else
					cout &lt;&lt; &quot;\t\t\t&quot;;

				cout &lt;&lt; zeilen.at( j ) &lt;&lt; endl;
			}
			break;
		}
	if( leer )
		cout &lt;&lt; &quot;keine eintraege vorhanden!&quot; &lt;&lt; endl;
	return 0;
}
</code></pre>
<p>zugegeben, wirklich schoen ist das nicht, aber es funktioniert gut.</p>
<p>mfg,<br />
julian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352550</guid><dc:creator><![CDATA[Julian__]]></dc:creator><pubDate>Sun, 26 Aug 2007 18:47:30 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Sun, 26 Aug 2007 20:35:37 GMT]]></title><description><![CDATA[<p>Vielen Dank,<br />
jetz funktioniert es endlich *fg* ich bekomme zwar noch 5 Warnungen, aber das Programm lässt sich endlich ohne Fehlermeldung compilieren<br />
vg KKaiser</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352617</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352617</guid><dc:creator><![CDATA[KKaiser]]></dc:creator><pubDate>Sun, 26 Aug 2007 20:35:37 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Mon, 27 Aug 2007 07:15:15 GMT]]></title><description><![CDATA[<p>Wenn das alles C4786-Warnungen wie oben sind, kannst du die gefahrlos ignorieren (die sagen lediglich aus, daß die angegebenen Namen zu lang sind für deinen Debugger).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1352720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1352720</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 27 Aug 2007 07:15:15 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Mon, 27 Aug 2007 12:39:36 GMT]]></title><description><![CDATA[<p>es gibt bei den for-schleifen ein paar warnungen, weil man signed- und unsigned-int vergleicht.<br />
sollte hier aber keine probleme geben.</p>
<p>mfg,<br />
julian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353004</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353004</guid><dc:creator><![CDATA[Julian__]]></dc:creator><pubDate>Mon, 27 Aug 2007 12:39:36 GMT</pubDate></item><item><title><![CDATA[Reply to Zeile für Zeile aus Textdatei auslesen on Mon, 27 Aug 2007 12:40:45 GMT]]></title><description><![CDATA[<p>Ok Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353006</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353006</guid><dc:creator><![CDATA[KKaiser]]></dc:creator><pubDate>Mon, 27 Aug 2007 12:40:45 GMT</pubDate></item></channel></rss>