<?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 einlesen]]></title><description><![CDATA[<p>Guten Abend</p>
<p>Meine Textdatei sieht wiefolgt aus</p>
<pre><code>nr.	X	Y
1	91	5
2	56	77
3	79	89
4	12	46
5	97	22
6	90	9
7	80	30
8	62	26
9	5	45
10	32	36
</code></pre>
<p>Ich möchte die x und y Koordinaten auslesen und speichern<br />
Ich bekomme allerdings nur 0en.</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;fstream&gt;
using namespace std;

struct kunde														//Struktur Kunde
{
	double x;
	double y;
};

vector&lt;kunde&gt; daten;												//Vektor für Kundendaten

void main()
{
	ifstream infile(&quot;Text.txt&quot;);									//Textdatei einlesen und Koordinaten in Vektor daten speichern
	for (int i=1; i&lt;=10; i++)											
	{
		kunde knd;
		for (int j=0; j&lt;3; j++)
		{
			double data(0);
			infile &gt;&gt; data;
			if (j==1)
			{
				knd.x = data;
			}			
			if (j==2)
			{
				knd.y = data;

			}
		}
		daten.push_back(knd);	

	}	
	infile.close();													//Textdatei wieder schließen

	system(&quot;pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/322335/textdatei-einlesen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 03:51:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322335.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Dec 2013 22:04:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:04:10 GMT]]></title><description><![CDATA[<p>Guten Abend</p>
<p>Meine Textdatei sieht wiefolgt aus</p>
<pre><code>nr.	X	Y
1	91	5
2	56	77
3	79	89
4	12	46
5	97	22
6	90	9
7	80	30
8	62	26
9	5	45
10	32	36
</code></pre>
<p>Ich möchte die x und y Koordinaten auslesen und speichern<br />
Ich bekomme allerdings nur 0en.</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;fstream&gt;
using namespace std;

struct kunde														//Struktur Kunde
{
	double x;
	double y;
};

vector&lt;kunde&gt; daten;												//Vektor für Kundendaten

void main()
{
	ifstream infile(&quot;Text.txt&quot;);									//Textdatei einlesen und Koordinaten in Vektor daten speichern
	for (int i=1; i&lt;=10; i++)											
	{
		kunde knd;
		for (int j=0; j&lt;3; j++)
		{
			double data(0);
			infile &gt;&gt; data;
			if (j==1)
			{
				knd.x = data;
			}			
			if (j==2)
			{
				knd.y = data;

			}
		}
		daten.push_back(knd);	

	}	
	infile.close();													//Textdatei wieder schließen

	system(&quot;pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2372079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372079</guid><dc:creator><![CDATA[ide]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:04:10 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:05:57 GMT]]></title><description><![CDATA[<p>Du musst irgendwie die erste Zeile überspringen, da steht nur Müll drin (jedenfalls kein double). Möglichkeiten wären cin.ignore und cin.getline.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372081</guid><dc:creator><![CDATA[springer]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:05:57 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:23:01 GMT]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
#include &lt;stdexcept&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;limits&gt;
#include &lt;map&gt;
struct Customer
{
    double X;
	double Y;
	explicit Customer(double X = 0., double Y = 0.)
		: X(X), Y(Y)
	{
	}
};
template&lt;typename CharT&gt;
std::basic_istream&lt;CharT&gt;&amp; operator&gt;&gt; (std::basic_istream&lt;CharT&gt;&amp; Stream, Customer&amp; Object)
{
	if(!(Stream &gt;&gt; Object.X) || !(Stream &gt;&gt; Object.Y))
	{
		throw std::invalid_argument(std::string(&quot;Couldn't parse input&quot;));
	}
	return Stream;
}
template&lt;typename CharT, typename Traits&gt;
std::basic_ostream&lt;CharT, Traits&gt;&amp; operator&lt;&lt; (std::basic_ostream&lt;CharT, Traits&gt;&amp; Stream, Customer const&amp; Object)
{
	::std::basic_ostringstream&lt;CharT, Traits&gt; StrStream;
	StrStream.flags(Stream.flags());
	StrStream.imbue(Stream.getloc());
	StrStream.precision(Stream.precision());

	StrStream &lt;&lt; Object.X &lt;&lt; '\t' &lt;&lt; Object.Y;

	return Stream &lt;&lt; StrStream.str();
}
int main()
{
    std::istream&amp; Source = std::cin;
	Source.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
	typedef std::map&lt;unsigned, Customer&gt; ListType;
	ListType List;
	{
		unsigned Nr;
		Customer InputCustomer;
		try
		{
			while((Source &gt;&gt; Nr) &amp;&amp; (Source &gt;&gt; InputCustomer))
			{
				List[Nr] = InputCustomer;
			}
		}
		catch(std::invalid_argument const&amp; Exception)
		{
			std::cerr &lt;&lt; Exception.what();
			return -1;
		}
	}
	std::cout &lt;&lt; &quot;Nr.\tX\tY\n&quot;;
	for(ListType::const_iterator i = List.begin(); i != List.end(); ++i)
	{
		std::cout &lt;&lt; i-&gt;first &lt;&lt; '\t' &lt;&lt; i-&gt;second &lt;&lt; '\n';
	}
}
</code></pre>
<p><a href="http://ideone.com/YPU2iS" rel="nofollow">http://ideone.com/YPU2iS</a></p>
<p>edit: wenn du - wie bei deinem code - aus der datei lesen willst, dann initialisiere die referenz &quot;Source&quot; einfach mit deinem ifstream.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372082</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:23:01 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:37:18 GMT]]></title><description><![CDATA[<p>Puh so gut bin ich leider in C++ noch nicht das ich da viel von verstehe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Kann man nicht irgendwie mit 1-2 Zeilen schreiben das er einfach ab Zeile 2 beginnen soll ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372083</guid><dc:creator><![CDATA[ide]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:37:18 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:38:13 GMT]]></title><description><![CDATA[<p>ide schrieb:</p>
<blockquote>
<p>Puh so gut bin ich leider in C++ noch nicht das ich da viel von verstehe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Kann man nicht irgendwie mit 1-2 Zeilen schreiben das er einfach ab Zeile 2 beginnen soll ?</p>
</blockquote>
<p>doch, siehe bei mir zeile 40.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372084</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:38:13 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:45:31 GMT]]></title><description><![CDATA[<pre><code>throw std::invalid_argument(std::string(&quot;Couldn't parse input&quot;))
</code></pre>
<p>... wieso die Konvertierung zu <code>string</code> ?</p>
<pre><code>::std::basic_ostringstream&lt;CharT, Traits&gt;
</code></pre>
<p>Ebenfalls überflüssiger Unsinn. Alles. Das :: vor dem <code>std</code> , sowie die templateisierung des Zeichentypen, und und und.<br />
Völlig overengineered.</p>
<blockquote>
<p>Möglichkeiten wären cin.ignore und cin.getline.</p>
</blockquote>
<p>Letzteres ist hier Fehl am Platz.</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;sstream&gt;
#include &lt;limits&gt;
using namespace std;

struct Kunde
{
	double x;
	double y;
};

istream&amp; operator&gt;&gt;( istream&amp; is, Kunde&amp; k )
{
	return is &gt;&gt; k.x &gt;&gt; k.y;
}

ostream&amp; operator&lt;&lt;( ostream&amp; os, Kunde const&amp; k )
{
	return os &lt;&lt; k.x &lt;&lt; ' ' &lt;&lt; k.y;
}

int main()
{
	// Repräsentiert Datei
	istringstream stream(
R&quot;(nr. X   Y
1   91  5
2   56  77
3   79  89
4   12  46
5   97  22
6   90  9
7   80  30
8   62  26
9   5   45
10  32  36)&quot;);

	stream.ignore( numeric_limits&lt;streamsize&gt;::max(), '\n' );

	vector&lt;Kunde&gt; daten;

	Kunde tmp;
	while( stream.ignore(10, ' ') &gt;&gt; tmp )
		daten.emplace_back(tmp);

	for( auto k : daten )
		std::cout &lt;&lt; k &lt;&lt; '\n';
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2372085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372085</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:45:31 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Sun, 15 Dec 2013 22:59:52 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<pre><code>throw std::invalid_argument(std::string(&quot;Couldn't parse input&quot;))
</code></pre>
<p>... wieso die Konvertierung zu <code>string</code> ?</p>
</blockquote>
<p><s>weil c++03</s><br />
falsch erinnert, hast recht, ist unnötig.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<pre><code>::std::basic_ostringstream&lt;CharT, Traits&gt;
</code></pre>
<p>Ebenfalls überflüssiger Unsinn. Alles. Das :: vor dem <code>std</code> , sowie die templateisierung des Zeichentypen, und und und.<br />
Völlig overengineered.</p>
</blockquote>
<p>ups, das führende :: war nicht beabsichtigt. ist, weil ich normalerweise nichts im globalen namensbereich schreibe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372086</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sun, 15 Dec 2013 22:59:52 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Mon, 16 Dec 2013 11:26:08 GMT]]></title><description><![CDATA[<p>würde das dann bei meinem Code mit infile.ignore() oder infile.getline() funktionieren ? Bloß was müsste dann in die Klammern ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372142</guid><dc:creator><![CDATA[ide]]></dc:creator><pubDate>Mon, 16 Dec 2013 11:26:08 GMT</pubDate></item><item><title><![CDATA[Reply to Textdatei einlesen on Mon, 16 Dec 2013 11:36:06 GMT]]></title><description><![CDATA[<p>ide schrieb:</p>
<blockquote>
<p>würde das dann bei meinem Code mit infile.ignore() oder infile.getline() funktionieren ?</p>
</blockquote>
<p>was steht bei mir im code in zeile 40? worauf habe ich explizit in meinem zweiten post hingewiesen? was hat Arcoth unter die dritte quote hingeschrieben? was steht in Arcoths code in zeile 39?</p>
<p>ide schrieb:</p>
<blockquote>
<p>Bloß was müsste dann in die Klammern ?</p>
</blockquote>
<p>das steht in der c++-referenz deiner wahl:<br />
<a href="http://en.cppreference.com/w/cpp/io/basic_istream/ignore" rel="nofollow">http://en.cppreference.com/w/cpp/io/basic_istream/ignore</a><br />
<a href="http://www.cplusplus.com/reference/istream/basic_istream/ignore/" rel="nofollow">http://www.cplusplus.com/reference/istream/basic_istream/ignore/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2372147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2372147</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 16 Dec 2013 11:36:06 GMT</pubDate></item></channel></rss>