<?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[txt in eine liste]]></title><description><![CDATA[<p>Hallo ich möchte eine txt datei in eine Liste laden.<br />
Die txt Datei sieht wie folgt aus:<br />
A 3 10 9<br />
B 2 3 5<br />
C 1 4 4<br />
D 2 2 6</p>
<p>das möchte ich in eine map einlesen<br />
hab es so versucht:<br />
typedef std::multimap&lt;string,int,int,int &gt; mmid;</p>
<p>so liefert mir der compiler aber edliche fehler. was mach ich falsch? und wie kann ich aus der txt in die liste einlesen.<br />
im moment habe ich es so gelöst das ich die einzelnen spalten in arrays einlese.<br />
wäre super wenn mir jemand helfen könnte.</p>
<p>campino</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/128565/txt-in-eine-liste</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 17:22:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/128565.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Dec 2005 23:09:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to txt in eine liste on Sun, 04 Dec 2005 23:09:55 GMT]]></title><description><![CDATA[<p>Hallo ich möchte eine txt datei in eine Liste laden.<br />
Die txt Datei sieht wie folgt aus:<br />
A 3 10 9<br />
B 2 3 5<br />
C 1 4 4<br />
D 2 2 6</p>
<p>das möchte ich in eine map einlesen<br />
hab es so versucht:<br />
typedef std::multimap&lt;string,int,int,int &gt; mmid;</p>
<p>so liefert mir der compiler aber edliche fehler. was mach ich falsch? und wie kann ich aus der txt in die liste einlesen.<br />
im moment habe ich es so gelöst das ich die einzelnen spalten in arrays einlese.<br />
wäre super wenn mir jemand helfen könnte.</p>
<p>campino</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934561</guid><dc:creator><![CDATA[campinoaf]]></dc:creator><pubDate>Sun, 04 Dec 2005 23:09:55 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Sun, 04 Dec 2005 23:40:28 GMT]]></title><description><![CDATA[<p>eine multimap ist keine map mit beliebig vielen values/keys,<br />
so erlaubt afaik nur das keys mehrmals vorkommen können.<br />
wie wäre es mit einem struct das 3 ints bzw nen array von 3 ints hat.<br />
dann könntest du ne map<a href="std::string,struct_t" rel="nofollow">std::string,struct_t</a> nehmen.<br />
oder nen set&lt;std::pair<a href="std::string,struct_t" rel="nofollow">std::string,struct_t</a> &gt; ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934565</guid><dc:creator><![CDATA[shapeless]]></dc:creator><pubDate>Sun, 04 Dec 2005 23:40:28 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Sun, 04 Dec 2005 23:51:29 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>danke für deine antwort.</p>
<p>ja wenn ich das mit struct und arrays mache. lassen die sich dann auch so einfach sortieren.<br />
wenn ich jetzt z.b. nach spalte 2 sortieren will müssen die anderen elemente sich ja auch anpassen.</p>
<p>campino</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934568</guid><dc:creator><![CDATA[campinoaf]]></dc:creator><pubDate>Sun, 04 Dec 2005 23:51:29 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 00:05:30 GMT]]></title><description><![CDATA[<p>naja dann würde ich ggf eine struct mit string und array oder 3 ints nehmen,<br />
und nen vector&lt;struct_t&gt;<br />
dann könntest du 3 sortier funktionen schreiben bzw eine templatefunktion die die art der sortierung bekommt-</p>
<p>also quasi ne funktoin<br />
second_less(struct_t one,struct_t other){// wenns nach dem 2ten gehen soll<br />
return one.sec&lt;other.sec;<br />
}</p>
<p>dann nen sort und dann deine vergleichsfunktion benutzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934570</guid><dc:creator><![CDATA[shapeless]]></dc:creator><pubDate>Mon, 05 Dec 2005 00:05:30 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 00:29:52 GMT]]></title><description><![CDATA[<p>also hier mal nen kleiner ansatz. vll kann er dir ja helfen:</p>
<pre><code class="language-cpp">struct data_t{
	int a_,b_,c_;
	std::string str_;
	data_t(int a,int b,int c,const std::string&amp; d):a_(a),b_(b),c_(c),str_(d){}
};

// deine sorter:
const bool sort_first(const data_t &amp;a,const data_t &amp;b){
	return a.a_&lt;b.a_;
}

const bool sort_sec(const data_t &amp;a,const data_t &amp;b){
	return a.b_&lt;b.b_;
}

const bool sort_third(const data_t &amp;a,const data_t &amp;b){
	return a.c_&lt;b.c_;
}
const bool sort_str(const data_t &amp;a,const data_t &amp;b){
	return a.str_&lt;b.str_;
}
[...]

	std::vector&lt;data_t&gt; db;
// den vector füllen

// eine der 4 funktionen benutzen
	std::sort(db.begin(),db.end(),sort_first);//oder sec oder third
	std::sort(db.begin(),db.end(),sort_str);
</code></pre>
<p>das bsp bezieht sich hier aber nur auf die sortierung.<br />
klassendesign kapselung und oder memberfunktionen usw hab ich mal ausser acht gelassen um das wesentliche zu zeigen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934574</guid><dc:creator><![CDATA[shapeless]]></dc:creator><pubDate>Mon, 05 Dec 2005 00:29:52 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 12:09:14 GMT]]></title><description><![CDATA[<p>danke für deine mühe.<br />
aber wie bekomm ich jetzt die werte aus der txt in meinen struct bzw. vector?<br />
ich versteh nicht wie man den vector jetzt mit werten füllt.<br />
und wnn ich jetzt sortiere soirtiert er mir immer nur eine spalte oder? ich will wenn ich nach 1. spalte sotiere das sich die anderen auch mit verndern weil sie unmittelbar zusammenhängen.</p>
<p>campino</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934855</guid><dc:creator><![CDATA[campinoaf]]></dc:creator><pubDate>Mon, 05 Dec 2005 12:09:14 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 12:24:45 GMT]]></title><description><![CDATA[<p>Als erstes schreibst du dir eine kleine Funktion, die dir einen einzelnen struct aus der Datei liest:</p>
<pre><code class="language-cpp">istream&amp; operator&gt;&gt;(istream&amp; sin,data_t&amp; data);
{
  sin&gt;&gt;data.str_&gt;&gt;data.a_&gt;&gt;data.b_&gt;&gt;data.c_;
  sin.ignore(1000);//Rest der Zeile wird ignoriert
  return sin;
}
</code></pre>
<p>Als nächstes kannst du diesen Operator in eine Schleife einbauen, die deinen Vektor füllt:</p>
<pre><code class="language-cpp">vector&lt;data_t&gt; werte;
ifstream fin(&quot;werte.txt&quot;);
data_t a_wert;
while(fin&gt;&gt;a_wert)          //struct einlesen
  werte.push_back(a_wert);  //in Vektor packen
</code></pre>
<p>PS: Die Struktur ist eine Einheit - wenn du dort etwas sortierst, werden die kompletten Datensätze umgeordnet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934864</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Dec 2005 12:24:45 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 12:52:02 GMT]]></title><description><![CDATA[<p>ok danke,</p>
<p>ich hab gerade versucht den vector auszulesen mit einem iterrator doch das kalppt nicht. muss ich dazu den ausgabeoperator auch überladen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934887</guid><dc:creator><![CDATA[campinoaf]]></dc:creator><pubDate>Mon, 05 Dec 2005 12:52:02 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 12:54:26 GMT]]></title><description><![CDATA[<p>Du kannst, du kannst aber auch direkt auf die Elemente zugreifen:</p>
<pre><code class="language-cpp">for(vector&lt;data_t&gt;::iterator pos=werte.begin();pos!=werte.end();++pos)
  cout&lt;&lt;pos-&gt;str_&lt;&lt;' '&lt;&lt;pos-&gt;a_ /*und so weiter*/;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/934891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934891</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Dec 2005 12:54:26 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 13:14:19 GMT]]></title><description><![CDATA[<p>hi also mein progg sieht jetzt so aus:</p>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;;
using std::string;
using std::cout;
using std::cin;
using std::ostream;
using std::istream;
using std::ifstream;
using std::vector;

struct data_t
{
    int a_,b_,c_;
    std::string str_;
    /*data_t(int a,int b,int c,const std::string&amp; d):a_(a),b_(b),c_(c),str_(d)
	{
	}*/
};

ostream &amp;operator&lt;&lt;(ostream &amp;output,data_t &amp;num)
{
	output&lt;&lt;num.a_;
	return output;
}

istream &amp;operator&gt;&gt;(istream&amp; sin,data_t&amp; data)
{
  sin&gt;&gt;data.str_&gt;&gt;data.a_&gt;&gt;data.b_&gt;&gt;data.c_;
  sin.ignore(1000);
  return sin;
}

const bool sort_first(const data_t &amp;a,const data_t &amp;b){
    return a.a_&lt;b.a_;
}

const bool sort_sec(const data_t &amp;a,const data_t &amp;b){
    return a.b_&lt;b.b_;
}

const bool sort_third(const data_t &amp;a,const data_t &amp;b){
    return a.c_&lt;b.c_;
}
const bool sort_str(const data_t &amp;a,const data_t &amp;b){
    return a.str_&lt;b.str_;
}

int _tmain(int argc, _TCHAR* argv[])
{
	vector&lt;data_t&gt; liste;
	ifstream file(&quot;werte.txt&quot;);
	data_t wert;
	while(file&gt;&gt;wert)          //struct einlesen
		liste.push_back(wert); 

	std::vector&lt;data_t&gt;::const_iterator iter;
	cout&lt;&lt;liste.size();
    //std::sort(db.begin(),db.end(),sort_first);//oder sec oder third
    //std::sort(db.begin(),db.end(),sort_str);

	for(iter=liste.begin(); iter!=liste.end();iter++)
	{
		cout&lt;&lt;liste[2];
	}
	cin.get();
	return 0;
}
</code></pre>
<p>er liest mir aber das file nicht ein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/934904</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934904</guid><dc:creator><![CDATA[campinoaf]]></dc:creator><pubDate>Mon, 05 Dec 2005 13:14:19 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 14:18:05 GMT]]></title><description><![CDATA[<p>Erstens: Mit was für einem Fehler meldet sich der Compiler?</p>
<p>Zweitens:</p>
<p>campinoaf schrieb:</p>
<blockquote>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;;
using std::string;
using std::cout;
using std::cin;
using std::ostream;
using std::istream;
using std::ifstream;
using std::vector;
</code></pre>
</blockquote>
<p>Zum Sortieren fehlt da noch:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
using std::sort;
</code></pre>
<p>(oder du verwendest gleich &quot;using namespace std;&quot;)</p>
<blockquote>
<pre><code>const bool sort_first(const data_t &amp;a,const data_t &amp;b){
    return a.a_&lt;b.a_;
}
</code></pre>
</blockquote>
<p>das &quot;const&quot; im Rückgabetyp ist wohl überflüssig.</p>
<blockquote>
<pre><code>for(iter=liste.begin(); iter!=liste.end();iter++)
  {
    cout&lt;&lt;liste[2];
  }
</code></pre>
</blockquote>
<p>Was soll denn das werden? Du schreibst n-mal das dritte Element deiner Liste:</p>
<pre><code class="language-cpp">cout&lt;&lt;*iter;
</code></pre>
<p>PS: Stimmt eigentlich der Name deiner Eingabedatei?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/934940</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934940</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Dec 2005 14:18:05 GMT</pubDate></item><item><title><![CDATA[Reply to txt in eine liste on Mon, 05 Dec 2005 14:34:45 GMT]]></title><description><![CDATA[<p>jetzt hat es doch geklappt, dank euch <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/934961</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/934961</guid><dc:creator><![CDATA[campinoaf]]></dc:creator><pubDate>Mon, 05 Dec 2005 14:34:45 GMT</pubDate></item></channel></rss>