<?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[Problem: 2-dimensionale Map]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgendes Problem:</p>
<p>Ich habe eine Datei:</p>
<pre><code># Kommentar
# ab   cd   ef    gh
# Zeile 1
   0.1  2.3  4.3  off
# Zeile 2
   0.2  5.6  7.6  on
# Zeile 3
   0.3  8.7  9.8  on
</code></pre>
<p>Nun muss ich die Datei einlesen und auf die Werte zugreifen können.</p>
<p>Das Ganze soll jetzt mit einer 2-dimensionalen Map realisiert werden, so dass man dann z.B. über test [1] [&quot;ef&quot;] auf den Wert 4.3 zugreifen kann.</p>
<p>Irgendwie weiß ich jetzt aber gar nicht, wie ich da anfangen soll...</p>
<p>Angelehnt daran, wie die Funktion vorher ausgesehen hat, hab ich jetzt mal angefangen, ein bißchen rumzuprobieren, aber irgendwie will das nicht funktionieren...</p>
<p>Das kann man alles mit Sicherheit noch viel besser lösen, aber ich bin ja jetzt nicht so der Profi... : <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>
<pre><code class="language-cpp">bool read()
{
    vector&lt;string&gt; lines;
    int i;
    ifstream IN (&quot;datei.txt&quot;);
    if (IN.is_open())
    {
        string line;
        while (getline(IN, line))
        {
            if (!line.empty() &amp;&amp; line[0] != '#')
            {
                lines.push_back(line);
                stringstream sstr;
                string gh;
                double ab, cd, ef;
                sstr &lt;&lt; lines[i-1];
                sstr &gt;&gt; ab &gt;&gt; cd &gt;&gt; ef &gt;&gt; gh;
                if (gh == &quot;on&quot;)
                {
                    vector &lt;double&gt; v;
                    v.push_back(ab);
                    v.push_back(cd);
                    v.push_back(ef);

                    test [&quot;ab&quot;] = v[0];
                    test [&quot;cd&quot;] = v[1];
                    test [&quot;ef&quot;] = v[2];
                }
                else
                {
                    cout&lt;&lt;&quot;line &quot;&lt;&lt;i&lt;&lt;&quot; is off\n&quot;;
                }
            }
        }
    IN.close();
    return true;
    }
    else
    {
        cout&lt;&lt;&quot;ERROR\n&quot;;
        return false;
    }
}
</code></pre>
<p>Das Problem ist, dass ich halt nicht auf die bestimmte Zeile zugreifen kann, auf die ich gerne möchte.</p>
<p>Könnt ihr mir da vielleicht weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/204221/problem-2-dimensionale-map</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 08:53:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/204221.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 Jan 2008 13:10:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem: 2-dimensionale Map on Thu, 31 Jan 2008 13:10:15 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgendes Problem:</p>
<p>Ich habe eine Datei:</p>
<pre><code># Kommentar
# ab   cd   ef    gh
# Zeile 1
   0.1  2.3  4.3  off
# Zeile 2
   0.2  5.6  7.6  on
# Zeile 3
   0.3  8.7  9.8  on
</code></pre>
<p>Nun muss ich die Datei einlesen und auf die Werte zugreifen können.</p>
<p>Das Ganze soll jetzt mit einer 2-dimensionalen Map realisiert werden, so dass man dann z.B. über test [1] [&quot;ef&quot;] auf den Wert 4.3 zugreifen kann.</p>
<p>Irgendwie weiß ich jetzt aber gar nicht, wie ich da anfangen soll...</p>
<p>Angelehnt daran, wie die Funktion vorher ausgesehen hat, hab ich jetzt mal angefangen, ein bißchen rumzuprobieren, aber irgendwie will das nicht funktionieren...</p>
<p>Das kann man alles mit Sicherheit noch viel besser lösen, aber ich bin ja jetzt nicht so der Profi... : <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>
<pre><code class="language-cpp">bool read()
{
    vector&lt;string&gt; lines;
    int i;
    ifstream IN (&quot;datei.txt&quot;);
    if (IN.is_open())
    {
        string line;
        while (getline(IN, line))
        {
            if (!line.empty() &amp;&amp; line[0] != '#')
            {
                lines.push_back(line);
                stringstream sstr;
                string gh;
                double ab, cd, ef;
                sstr &lt;&lt; lines[i-1];
                sstr &gt;&gt; ab &gt;&gt; cd &gt;&gt; ef &gt;&gt; gh;
                if (gh == &quot;on&quot;)
                {
                    vector &lt;double&gt; v;
                    v.push_back(ab);
                    v.push_back(cd);
                    v.push_back(ef);

                    test [&quot;ab&quot;] = v[0];
                    test [&quot;cd&quot;] = v[1];
                    test [&quot;ef&quot;] = v[2];
                }
                else
                {
                    cout&lt;&lt;&quot;line &quot;&lt;&lt;i&lt;&lt;&quot; is off\n&quot;;
                }
            }
        }
    IN.close();
    return true;
    }
    else
    {
        cout&lt;&lt;&quot;ERROR\n&quot;;
        return false;
    }
}
</code></pre>
<p>Das Problem ist, dass ich halt nicht auf die bestimmte Zeile zugreifen kann, auf die ich gerne möchte.</p>
<p>Könnt ihr mir da vielleicht weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1446939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1446939</guid><dc:creator><![CDATA[LadyM]]></dc:creator><pubDate>Thu, 31 Jan 2008 13:10:15 GMT</pubDate></item><item><title><![CDATA[Reply to Problem: 2-dimensionale Map on Thu, 31 Jan 2008 13:23:04 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Was hat denn test für einen Typ? Ich würde hier sowas wie</p>
<pre><code class="language-cpp">vector&lt;map&lt;string,double&gt; &gt;
</code></pre>
<p>nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1446951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1446951</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 31 Jan 2008 13:23:04 GMT</pubDate></item><item><title><![CDATA[Reply to Problem: 2-dimensionale Map on Thu, 31 Jan 2008 13:31:38 GMT]]></title><description><![CDATA[<p>Eigentlich sah die map irgendwie so aus:<br />
map&lt;int, map&lt;string, double&gt; &gt;</p>
<p>Aber wenn ich dann als Integer z.B. die Zeile 2 übergebe, dann weiß ich nicht, wie ich das in der Funktion schreiben soll, weil das ja dann dem lines[2-1] entspricht, was ja ein string ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1446965</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1446965</guid><dc:creator><![CDATA[LadyM]]></dc:creator><pubDate>Thu, 31 Jan 2008 13:31:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem: 2-dimensionale Map on Thu, 31 Jan 2008 14:04:39 GMT]]></title><description><![CDATA[<p>Mach doch einfach ein struct und definier für den einen Stream-Operator.</p>
<pre><code class="language-cpp">struct Entry{
  double ab;
  double cd;
  double ef;
  std::string gh;
};

istream &amp;operator&gt;&gt;(istream &amp;stream, Entry &amp;entry){
  stream &gt;&gt; ab &gt;&gt; cd &gt;&gt; ef &gt;&gt; gh;
  return stream;
}
</code></pre>
<p>Müsste so stimmen, glaube ich. Nicht getestet.</p>
<p>Dann kannst du einfach:</p>
<pre><code class="language-cpp">Entry entry;
stream &gt;&gt; entry;
</code></pre>
<p>schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1447001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1447001</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 31 Jan 2008 14:04:39 GMT</pubDate></item></channel></rss>