<?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[getline]]></title><description><![CDATA[<p>Guten Tag</p>
<p>Ich möchte mit getline aus einer Datei Text einlesen und diesen dann irgendwann<br />
während dem Programm in Teilen aufrufen.</p>
<p>Beispiel</p>
<p>text.txt</p>
<p>Dies ist der erste satz im ersten Teil. dies ist der zweite Satz im ersten Teil.<br />
Nun beginnt der zweite Absatz mit dem ersten Satz. Zweiter Satz. Dritter Satz, imemr noch dritter Satz. Vierter satz.<br />
3 Teil erster Satz...</p>
<p>Wie kann ich das machen ich hab mal was von Trennzeichen gelesen.</p>
<p>ich habe es versucht mit:</p>
<pre><code class="language-cpp">[code]
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

using namespace std;

int main () {
  string line;
  ifstream myfile (&quot;text.txt&quot;);
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      string s;
	vector &lt;string&gt; v;
	while (getline( myfile, s ))
	 {
	 v.push_back( s );
	}
	cout &lt;&lt; v[ 1 ] &lt;&lt; endl; 
	 }
    myfile.close();
   }

  else cout &lt;&lt; &quot;Unable to open file&quot;; 

  system(&quot;pause&quot;);
}[/code]
</code></pre>
<p>Jedoch lisst es 1. Den Ersten Satz nicht und 2tens möchte ich es bei spezifischen Zeichen trennen und dann den Text vor diesem Zeichen soll auf den ersten Vector(Array??) speichern.</p>
<p>Ich danke euch für eure Vorschläge bzw Tipps</p>
<p>Mit Freundlichen Grüssen</p>
<p>thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/302674/getline</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 05:47:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302674.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 Apr 2012 11:09:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 11:09:18 GMT]]></title><description><![CDATA[<p>Guten Tag</p>
<p>Ich möchte mit getline aus einer Datei Text einlesen und diesen dann irgendwann<br />
während dem Programm in Teilen aufrufen.</p>
<p>Beispiel</p>
<p>text.txt</p>
<p>Dies ist der erste satz im ersten Teil. dies ist der zweite Satz im ersten Teil.<br />
Nun beginnt der zweite Absatz mit dem ersten Satz. Zweiter Satz. Dritter Satz, imemr noch dritter Satz. Vierter satz.<br />
3 Teil erster Satz...</p>
<p>Wie kann ich das machen ich hab mal was von Trennzeichen gelesen.</p>
<p>ich habe es versucht mit:</p>
<pre><code class="language-cpp">[code]
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

using namespace std;

int main () {
  string line;
  ifstream myfile (&quot;text.txt&quot;);
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      string s;
	vector &lt;string&gt; v;
	while (getline( myfile, s ))
	 {
	 v.push_back( s );
	}
	cout &lt;&lt; v[ 1 ] &lt;&lt; endl; 
	 }
    myfile.close();
   }

  else cout &lt;&lt; &quot;Unable to open file&quot;; 

  system(&quot;pause&quot;);
}[/code]
</code></pre>
<p>Jedoch lisst es 1. Den Ersten Satz nicht und 2tens möchte ich es bei spezifischen Zeichen trennen und dann den Text vor diesem Zeichen soll auf den ersten Vector(Array??) speichern.</p>
<p>Ich danke euch für eure Vorschläge bzw Tipps</p>
<p>Mit Freundlichen Grüssen</p>
<p>thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205199</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205199</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Tue, 24 Apr 2012 11:09:18 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 11:19:15 GMT]]></title><description><![CDATA[<p>Wirre Fragestellung, ich rate mal was du möchtest:</p>
<pre><code class="language-cpp">for(string s; getline(myfile, s, '.'); v.push_back(s));
</code></pre>
<p>Wenn du Fragen zu Funktionen der Standardbibliothek hast, z.B. wie das mit den Trennzeichen geht, dann schau doch mal in eine Referenz:<br />
<a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">http://www.cplusplus.com/reference/string/getline/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205201</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 24 Apr 2012 11:19:15 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 11:30:40 GMT]]></title><description><![CDATA[<p>Gefällt dir jetzt auf meinen Vorschlag hin die for-Schleife generell besser? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205208</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Tue, 24 Apr 2012 11:30:40 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 11:33:47 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Wirre Fragestellung, ich rate mal was du möchtest:</p>
<pre><code class="language-cpp">for(string s; getline(myfile, s, '.'); v.push_back(s));
</code></pre>
<p>Wenn du Fragen zu Funktionen der Standardbibliothek hast, z.B. wie das mit den Trennzeichen geht, dann schau doch mal in eine Referenz:<br />
<a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">http://www.cplusplus.com/reference/string/getline/</a></p>
</blockquote>
<p>Ja genau ich möchte einfach das es den Text bis zum Trennzeichen jeweils auf einen Vector speichert.</p>
<p>mit deinem Code erhalte ich einen Error.</p>
<p>Falsch angepasst?</p>
<pre><code class="language-cpp">[code]
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

using namespace std;

int main () {
  string line;
  ifstream myfile (&quot;text.txt&quot;);
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
	string s;
	vector &lt;string&gt; v;
	for(string s; getline(myfile, s, '.');
	v.push_back(s));
	cout &lt;&lt; v[ 1 ] &lt;&lt; endl; 
	 }
    myfile.close();
   }

  else cout &lt;&lt; &quot;Unable to open file&quot;; 

  system(&quot;pause&quot;);
}[/code]
</code></pre>
<p>Gruss</p>
<p>Thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205209</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Tue, 24 Apr 2012 11:33:47 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 11:53:11 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Gefällt dir jetzt auf meinen Vorschlag hin die for-Schleife generell besser? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Ja <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<blockquote>
<p>mit deinem Code erhalte ich einen Error.</p>
</blockquote>
<p>Aha. Ich erhalte nur, dass system nicht bekannt ist, weil du cstdlib vergessen hast. Magst du vielleicht etwas genauer werden?</p>
<blockquote>
<p>Falsch angepasst?</p>
</blockquote>
<p>Auch. Mein Code war als Ersatz für all dein Gewusel gedacht. Ja, Ein- und Ausgabe kann man in C++ oft in 1-2 Zeilen schreiben, ohne umständliche verschachtelte Schleifenkonstrukte.</p>
<pre><code class="language-cpp">int main () 
{
  ifstream myfile (&quot;test.cc&quot;);
  vector &lt;string&gt; v;
  for(string s; getline(myfile, s, '.'); v.push_back(s));

  if (v.size() &gt;= 2) 
    cout &lt;&lt; v[ 1 ] &lt;&lt; '\n'; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2205218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205218</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 24 Apr 2012 11:53:11 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 12:12:58 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>314159265358979 schrieb:</p>
<blockquote>
<p>Gefällt dir jetzt auf meinen Vorschlag hin die for-Schleife generell besser? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Ja <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<blockquote>
<p>mit deinem Code erhalte ich einen Error.</p>
</blockquote>
<p>Aha. Ich erhalte nur, dass system nicht bekannt ist, weil du cstdlib vergessen hast. Magst du vielleicht etwas genauer werden?</p>
<blockquote>
<p>Falsch angepasst?</p>
</blockquote>
<p>Auch. Mein Code war als Ersatz für all dein Gewusel gedacht. Ja, Ein- und Ausgabe kann man in C++ oft in 1-2 Zeilen schreiben, ohne umständliche verschachtelte Schleifenkonstrukte.</p>
<pre><code class="language-cpp">int main () 
{
  ifstream myfile (&quot;test.cc&quot;);
  vector &lt;string&gt; v;
  for(string s; getline(myfile, s, '.'); v.push_back(s));

  if (v.size() &gt;= 2) 
    cout &lt;&lt; v[ 1 ] &lt;&lt; '\n'; 
}
</code></pre>
</blockquote>
<p>autsch! Bin ich dumm xD</p>
<p>Vielen vielen Dank für deine Hilfe jetzt habe ich was ich gebraucht habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Gruss</p>
<p>thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205225</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Tue, 24 Apr 2012 12:12:58 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 12:35:01 GMT]]></title><description><![CDATA[<p>Ich hätte noch eine weitere Frage:</p>
<p>Habe mir jetzt was zusammen getragen was so aussieht:</p>
<p>waffe.h</p>
<pre><code class="language-cpp">[code]
#pragma once

#include &quot;stdafx.h&quot;

using namespace std;

class Waffe 
{ 
    public: 
    Waffe(string CName,string CDmg,string CKosten){Name = CName;Dmg = CDmg;Kosten=CKosten;} 
    string Name,Dmg,Kosten; 
}; 

class Waffenliste 
{ 
    public: 
    void add(Waffe item) 
    { 
        Liste.push_back(item); 
    } 
    vector&lt;Waffe&gt; Liste; 
};
</code></pre>
<p>[/code]</p>
<p>.cpp</p>
<pre><code class="language-cpp">[code]
// get_line.cpp : Defines the entry point for the console application.
//

#include &quot;stdafx.h&quot;

#include &quot;waffe.h&quot;

using namespace std;

int main () 
{ 
  ifstream myfile (&quot;text.txt&quot;);
  if(myfile.good()) 
	{ 
		while(!myfile.eof()) 
		{ 
			vector &lt;string&gt; v; 
			for(string s; getline(myfile, s, ';'); v.push_back(s)); 
				{
				  if (v.size() &gt;= 0)
				  {
					cout &lt;&lt; v[1] &lt;&lt; '\n'; 
					cout &lt;&lt; v[2] &lt;&lt; '\n'; 
					cout &lt;&lt; v[3] &lt;&lt; '\n'; 
					cout &lt;&lt; v[4] &lt;&lt; '\n'; 
					cout &lt;&lt; v[5] &lt;&lt; '\n'; 
				  }
				}
		}
	}
	myfile.close();

		Waffenliste liste; 
		ifstream file(&quot;waffe.txt&quot;); 
		if(file.good()) 
		{ 
			while(!file.eof()) 
			{ 
			vector&lt;string&gt; zeile; 
			string line; 
			getline(file,line); 
			 do 
				{ 
				//generiert Substring und fügt den gleich dem vektor hinzu 
					zeile.push_back(line.substr(0,line.find(&quot;;&quot;))); 
				//wenn danach noch ein leerzeichen kommt löscht er bis zu diesem sonst alles 
					if(line.find(&quot;;&quot;)!= string::npos) 
					line.erase(0,line.find(&quot;;&quot;)+1); 
					else 
					line.erase(); 
				} 
				while(!line.empty()); 
				liste.add(Waffe(zeile[0],zeile[1],zeile[2])); 
				} 

			} 
			file.close(); 
			for(unsigned int i = 0 ; i&lt;liste.Liste.size();i++) 
			cout &lt;&lt; &quot;Name: &quot; &lt;&lt; liste.Liste[i].Name &lt;&lt; &quot;(Dmg &quot; &lt;&lt; liste.Liste[i].Dmg &lt;&lt; &quot;,Kosten &quot; &lt;&lt; liste.Liste[i].Kosten &lt;&lt; &quot;)&quot; &lt;&lt; endl; 

  system(&quot;pause&quot;);
}
</code></pre>
<p>[/code]</p>
<p>Es gibt mir einen Fehler aus und ich kann nur &quot;Abort&quot;, &quot;Retry&quot; oder &quot;Ignor* klicken.</p>
<p>Was genau ist falsch?</p>
<p>Ich möchte das die sachen aus Textfile waffe.txt auf die kalsse eingelesen wird.</p>
<p>(Code hab ich aus einem anderem Theard)</p>
<p>Gruss</p>
<p>thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205227</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Tue, 24 Apr 2012 12:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 12:59:41 GMT]]></title><description><![CDATA[<p>Aha. Ein Fehler. Und man kann was klicken. Dann ist ja alles klar. Die Lösung ist einfach: Du musst die Schildfrequenz modulieren.</p>
<p>Magst du dir nicht mal die bisherigen Antworten anschauen und versuchen, aus diesen zu lernen? Der Code den du jetzt gezeigt hast ist wieder dieses grausame :C-Einleseschleife mit C++-Mitteln umgeschrieben&quot;, was zwar compilieren mag, aber logisch falsch ist, da die C++-Mittel eine andere Logik als die alten C-Funktionen haben. Und zwischendrin hast du dann noch meine Lösung zwischen lauter sinnlosen Kontrollstrukturen (da mein Schleifchen sich schon um alles kümmert, aber du hast es nicht verstanden) eingeklemmt. Wenn du Code schreibst, dann musst du ihn auch verstehen. Code ist Logik pur, kein Haufen von aneinanderkopierter Fetzen aus dem Internet. Du musst genau wissen, an welcher Stelle du warum welches Zeichen setzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205230</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 24 Apr 2012 12:59:41 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 12:53:04 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">vector &lt;string&gt; v; 
            for(string s; getline(myfile, s, ';'); v.push_back(s)); 
                {
                  if (v.size() &gt;= 0)
                  {
                    cout &lt;&lt; v[1] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[2] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[3] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[4] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[5] &lt;&lt; '\n'; 
                  }
                }
</code></pre>
<p>verursacht vermutlich den Fehler. <s>du hast nen Vector und sobald ein Element darin enthalten ist, versuchst du auf 5 zuzugreifen.</s> Warum genau willst du den inhalt des Vectors hier ausgeben?</p>
<p>edit: Mein Fehler, aber bei dieser Klammerung auch schwer zu lesen. Bist du sicher dass v nach Durchlauf der for-Schleife mindestens 6 Elemente enthält?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205231</guid><dc:creator><![CDATA[Dudemeister]]></dc:creator><pubDate>Tue, 24 Apr 2012 12:53:04 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 12:59:23 GMT]]></title><description><![CDATA[<p>Dudemeister schrieb:</p>
<blockquote>
<pre><code class="language-cpp">vector &lt;string&gt; v; 
            for(string s; getline(myfile, s, ';'); v.push_back(s)); 
                {
                  if (v.size() &gt;= 0)
                  {
                    cout &lt;&lt; v[1] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[2] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[3] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[4] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[5] &lt;&lt; '\n'; 
                  }
                }
</code></pre>
<p>verursacht vermutlich den Fehler. <s>du hast nen Vector und sobald ein Element darin enthalten ist, versuchst du auf 5 zuzugreifen.</s> Warum genau willst du den inhalt des Vectors hier ausgeben?</p>
<p>edit: Mein Fehler, aber bei dieser Klammerung auch schwer zu lesen. Bist du sicher dass v nach Durchlauf der for-Schleife mindestens 6 Elemente enthält?</p>
</blockquote>
<p>Die schleife selbst macht keinen Fehler wenn ich alles danach weglasse geht das ohne Problem.</p>
<p>Ich habe dort die Ausgabe gemacht nur weill ich sehen wollte was passiert um zu verstehen wie das ganze funktioniert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205233</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Tue, 24 Apr 2012 12:59:23 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 13:03:36 GMT]]></title><description><![CDATA[<p>Nunja, dann solltest du dein Programm mal debuggen. So ist deine beschreibung des Fehlers doch recht ungenau.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205235</guid><dc:creator><![CDATA[Dudemeister]]></dc:creator><pubDate>Tue, 24 Apr 2012 13:03:36 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 13:18:24 GMT]]></title><description><![CDATA[<p>Dudemeister schrieb:</p>
<blockquote>
<pre><code class="language-cpp">vector &lt;string&gt; v; 
            for(string s; getline(myfile, s, ';'); v.push_back(s)); 
                {
                  if (v.size() &gt;= 0)
                  {
                    cout &lt;&lt; v[1] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[2] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[3] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[4] &lt;&lt; '\n'; 
                    cout &lt;&lt; v[5] &lt;&lt; '\n'; 
                  }
                }
</code></pre>
</blockquote>
<p>Dir ist aber klar, das der Code nach der Schleife nur einmal ausgeführt wird, nachdem die Schleife durchgelaufen ist? Wenn nicht, schau mal ganze genau hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205237</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205237</guid><dc:creator><![CDATA[pyhax]]></dc:creator><pubDate>Tue, 24 Apr 2012 13:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 13:49:57 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/27772">@pyhax</a><br />
Ja das ist mir klar ^^<br />
Ich hab das ganze ja nur als Test eingebaut.<br />
Trozdem Danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24675">@Dudemeister</a><br />
Hab das Problem behoben jetzt sieht es so aus:</p>
<pre><code>// get_line.cpp : Defines the entry point for the console application.
//

#include &quot;stdafx.h&quot;

#include &quot;waffe.h&quot;

using namespace std;

int main () 
{ 
  ifstream myfile (&quot;text.txt&quot;);
  if(myfile.good()) 
	{ 
		while(!myfile.eof()) 
		{ 
			vector &lt;string&gt; v; 
			for(string s; getline(myfile, s, ';'); v.push_back(s)); 
				{
				  if (v.size() &gt;= 0)
				  {
					cout &lt;&lt; v[1] &lt;&lt; '\n'; 

				  }
				}
		}
	}
	myfile.close();
	Waffenliste liste; 
	ifstream file(&quot;waffe.txt&quot;); 
	if(file.good()) 
	{ 
		while(!file.eof()) 
		{ 
		vector&lt;string&gt; zeile; 
		string line; 
		getline(file,line); 
			do 
			{ 
			//generiert Substring und fügt den gleich dem vektor hinzu 
				zeile.push_back(line.substr(0,line.find(&quot;;&quot;))); 
			//wenn danach noch ein leerzeichen kommt löscht er bis zu diesem sonst alles 
				if(line.find(&quot; &quot;)!= string::npos) 
				{
					line.erase(0,line.find(&quot; &quot;)+1); 
				}
				else 
				{
					line.erase();
				}
			}
			while(!line.empty()); 
			liste.add(Waffe(zeile[0],zeile[1],zeile[2])); 
			} 
	}
	file.close();
	for(unsigned int i = 0 ; i&lt;liste.Liste.size();i++) 
	{
		cout &lt;&lt; &quot;Name: &quot; &lt;&lt; liste.Liste[i].Name &lt;&lt; &quot;(Dmg &quot; &lt;&lt; liste.Liste[i].Dmg &lt;&lt; &quot;,Kosten &quot; &lt;&lt; liste.Liste[i].Kosten &lt;&lt; &quot;)&quot; &lt;&lt; endl; 
	}
  system(&quot;pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2205250</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205250</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Tue, 24 Apr 2012 13:49:57 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Tue, 24 Apr 2012 14:11:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">vector &lt;string&gt; v; 
for(string s; getline(myfile, s, ';'); v.push_back(s)); 
{ 
   if (v.size() &gt;= 0) 
   { 
       cout &lt;&lt; v[1] &lt;&lt; '\n'; 
   } 
}
</code></pre>
<p>hmm... das sieht immernoch komisch aus. Was du zum testen haben willst ist vermutlich:</p>
<pre><code class="language-cpp">vector &lt;string&gt; v; 
for(string s; getline(myfile, s, ';'); v.push_back(s))  // hier kein ;
{ 
	cout &lt;&lt; s;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2205259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205259</guid><dc:creator><![CDATA[Dudemeister]]></dc:creator><pubDate>Tue, 24 Apr 2012 14:11:51 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Wed, 25 Apr 2012 06:07:47 GMT]]></title><description><![CDATA[<p>Dudemeister schrieb:</p>
<blockquote>
<pre><code class="language-cpp">vector &lt;string&gt; v; 
for(string s; getline(myfile, s, ';'); v.push_back(s)); 
{ 
   if (v.size() &gt;= 0) 
   { 
       cout &lt;&lt; v[1] &lt;&lt; '\n'; 
   } 
}
</code></pre>
<p>hmm... das sieht immernoch komisch aus. Was du zum testen haben willst ist vermutlich:</p>
<pre><code class="language-cpp">vector &lt;string&gt; v; 
for(string s; getline(myfile, s, ';'); v.push_back(s))  // hier kein ;
{ 
	cout &lt;&lt; s;
}
</code></pre>
</blockquote>
<p>Danke für deine Antwort.</p>
<p>Wenn ich das &quot;;&quot; weg neme stürzt das ganze Prog wieder ab.</p>
<p>Und wenn ich cout &lt;&lt; s; nehme erkennt es s nicht (weils s in der for schleife inizialisiert wird und nur in dessen Instanz funktioniert?)</p>
<p>Gruss</p>
<p>thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205401</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Wed, 25 Apr 2012 06:07:47 GMT</pubDate></item><item><title><![CDATA[Reply to getline on Wed, 25 Apr 2012 06:15:28 GMT]]></title><description><![CDATA[<p>Mit dem obenn geschribenen Code erhalte ich folgende Ausgabe:</p>
<p>Hallo und Herzlich willkommen<br />
Name: Speer&lt;Dmg 50, Kosten 20&gt;<br />
Name: Messer&lt;Dmg 30, Kosten 10&gt;<br />
Press any key to continue...</p>
<p>text.txt</p>
<pre><code>;Hallo und Herzlich willkommen;
</code></pre>
<p>waffe.txt</p>
<pre><code>Speer.50.20.
Messer.30.10.
</code></pre>
<p>Ich möchte jedoch die Ausgabe ohne die &lt; &gt; bei &lt;Dmg..&gt;</p>
<p>wie kommen diese Zustande und warum?</p>
<p>Gruss</p>
<p>thomas1234</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2205402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2205402</guid><dc:creator><![CDATA[thomas1234]]></dc:creator><pubDate>Wed, 25 Apr 2012 06:15:28 GMT</pubDate></item></channel></rss>