<?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[string problematik?]]></title><description><![CDATA[<p>Guten Abend Gemeinde,</p>
<pre><code class="language-cpp">int readFromFile()
	{
	cout &lt;&lt; &quot;Enter filename: &quot;;
	cin&gt;&gt; fileName;

	ifstream input(fileName.c_str(),ios::in);

    if (input.is_open())
    {
        while (getline(input, fileName))
        {
            istringstream istr (fileName); // &quot;A ; 1; 1&quot;
            if (istr &gt;&gt;Standort &amp;&amp; istr &gt;&gt; c &amp;&amp; c == ';' &amp;&amp; istr &gt;&gt; cordx &amp;&amp; istr &gt;&gt; c &amp;&amp; c == ';' &amp;&amp; istr &gt;&gt; cordy)
            {

				//map.addDest(Standort,cordx,cordy);
				cout &lt;&lt;fileName &lt;&lt;endl;
            }

        }

    }
    else
    {
        cout &lt;&lt; &quot;Datei nicht gefunden!&quot; &lt;&lt; endl;
		readFromFile();
    }
	cin.get();
	cin.sync();
    return 0;
	}
</code></pre>
<p>tsp.csv</p>
<pre><code>A ; 1; 1
B ; 7; 7
C ; 14; 5
D ; 3; 4
SehrWeitWeg; 4711; 1147
</code></pre>
<p>und zwar frisst er den string Standort nicht ohne Whitespace.<br />
sprich:</p>
<pre><code>SehrWeitWeg; 4711; 1147    ---&gt; geht nicht!
SehrWeitWeg ; 4711; 1147    ---&gt; geht!
</code></pre>
<p>bei den Zahlen ist es komischerweise egal..</p>
<p>PS: hat jemand eine schönere Variante für den else-Teil:</p>
<pre><code>cout &lt;&lt; &quot;Datei nicht gefunden!&quot; &lt;&lt; endl;
		[b]readFromFile();[/b]
</code></pre>
<p>gruß!!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/254450/string-problematik</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 09:20:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/254450.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Nov 2009 18:16:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to string problematik? on Mon, 16 Nov 2009 18:21:47 GMT]]></title><description><![CDATA[<p>Guten Abend Gemeinde,</p>
<pre><code class="language-cpp">int readFromFile()
	{
	cout &lt;&lt; &quot;Enter filename: &quot;;
	cin&gt;&gt; fileName;

	ifstream input(fileName.c_str(),ios::in);

    if (input.is_open())
    {
        while (getline(input, fileName))
        {
            istringstream istr (fileName); // &quot;A ; 1; 1&quot;
            if (istr &gt;&gt;Standort &amp;&amp; istr &gt;&gt; c &amp;&amp; c == ';' &amp;&amp; istr &gt;&gt; cordx &amp;&amp; istr &gt;&gt; c &amp;&amp; c == ';' &amp;&amp; istr &gt;&gt; cordy)
            {

				//map.addDest(Standort,cordx,cordy);
				cout &lt;&lt;fileName &lt;&lt;endl;
            }

        }

    }
    else
    {
        cout &lt;&lt; &quot;Datei nicht gefunden!&quot; &lt;&lt; endl;
		readFromFile();
    }
	cin.get();
	cin.sync();
    return 0;
	}
</code></pre>
<p>tsp.csv</p>
<pre><code>A ; 1; 1
B ; 7; 7
C ; 14; 5
D ; 3; 4
SehrWeitWeg; 4711; 1147
</code></pre>
<p>und zwar frisst er den string Standort nicht ohne Whitespace.<br />
sprich:</p>
<pre><code>SehrWeitWeg; 4711; 1147    ---&gt; geht nicht!
SehrWeitWeg ; 4711; 1147    ---&gt; geht!
</code></pre>
<p>bei den Zahlen ist es komischerweise egal..</p>
<p>PS: hat jemand eine schönere Variante für den else-Teil:</p>
<pre><code>cout &lt;&lt; &quot;Datei nicht gefunden!&quot; &lt;&lt; endl;
		[b]readFromFile();[/b]
</code></pre>
<p>gruß!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1808962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1808962</guid><dc:creator><![CDATA[pampy]]></dc:creator><pubDate>Mon, 16 Nov 2009 18:21:47 GMT</pubDate></item><item><title><![CDATA[Reply to string problematik? on Mon, 16 Nov 2009 20:35:19 GMT]]></title><description><![CDATA[<p>Ich würde gleich mal eine etwas allgemeinere Funktion dafür schreiben. Aus php bin ich rechter Fan von explode, also:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

std::vector&lt;std::string&gt; explode ( std::string input, char del, bool trim = true )
{
	std::vector&lt;std::string&gt; v;
	std::istringstream s( input );

	std::string temp;
	while ( std::getline ( s, temp, del ) )
	{
		if ( trim )
			temp.erase ( std::remove ( temp.begin (), temp.end (), ' '), temp.end () );

		v.push_back ( temp );
	}

	return v;
}

int main()
{
	std::string line = &quot;SehrWeitWeg; 4711; 1147 &quot;;

	std::vector&lt;std::string&gt; params = explode ( line, ';' );

	for (std::vector&lt;std::string&gt;::iterator it = params.begin (); it != params.end (); ++it )
		std::cout &lt;&lt; *it &lt;&lt; &quot; &quot;;
}
</code></pre>
<p>Das macht aus einer Zeile genau das erwartete. Nämlich eine Liste von Werten. Die sind halt noch in string Form, aber ich denke, dass du die Umwandlung in den gewünschten Datentypen noch selbt hinkriegst.</p>
<p>Für den else Part würde ich eine Schleife empfehlen. Kannst ja einen Parameter <code>successful</code> oder so haben, den du erst, wenn es geklappt hat auf true setzt und dann läuft das einfach so lange, bis es gelungen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1809048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1809048</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 16 Nov 2009 20:35:19 GMT</pubDate></item><item><title><![CDATA[Reply to string problematik? on Sat, 21 Nov 2009 20:30:22 GMT]]></title><description><![CDATA[<p>ok, danke hat sich erledigt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1811591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1811591</guid><dc:creator><![CDATA[pampy]]></dc:creator><pubDate>Sat, 21 Nov 2009 20:30:22 GMT</pubDate></item><item><title><![CDATA[Reply to string problematik? on Sun, 22 Nov 2009 14:57:36 GMT]]></title><description><![CDATA[<p>pampy schrieb:</p>
<blockquote>
<p>ok, danke hat sich erledigt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
</blockquote>
<p>s</p>
<p>Hast du es mit dem obigen Code gemacht, oder komplett anderst?</p>
<p>Wenn du es anderst gelöst hast, dann wäre es schön, wenn du die Lösung auch gleich postest.</p>
<p>Es gibt nix nervigeres, als wenn man auf der Suche nach der Lösung eines Problemes ist und man einen Thread findet, der genau das gleiche Problem hat und dann findet er eine Lösung, postet sie aber nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1811829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1811829</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 22 Nov 2009 14:57:36 GMT</pubDate></item><item><title><![CDATA[Reply to string problematik? on Sun, 22 Nov 2009 17:43:52 GMT]]></title><description><![CDATA[<p>so wie in deinem Post, ganz klar :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1811936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1811936</guid><dc:creator><![CDATA[pampy]]></dc:creator><pubDate>Sun, 22 Nov 2009 17:43:52 GMT</pubDate></item><item><title><![CDATA[Reply to string problematik? on Mon, 23 Nov 2009 04:57:16 GMT]]></title><description><![CDATA[<p><a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=381544#TokenizeString" rel="nofollow">http://www.gamedev.net/community/forums/topic.asp?topic_id=381544#TokenizeString</a></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

std::vector&lt;std::string&gt; TokenizeString(const std::string&amp; str, const std::string&amp; delim)
{
	using namespace std;
	vector&lt;string&gt; tokens;
	size_t p0 = 0, p1 = string::npos;
	while(p0 != string::npos)
	{
		p1 = str.find_first_of(delim, p0);
		if(p1 != p0)
		{
			string token = str.substr(p0, p1 - p0);
			tokens.push_back(token);
		}
		p0 = str.find_first_not_of(delim, p1);
	}
	return tokens;
}

int main(int argc, char* argv[])
{
	std::string source = &quot;This string will be tokenized by a vector of characters which are vowels&quot;;
	std::vector&lt;std::string&gt; tokens = TokenizeString(source, &quot;aeiou&quot;);

	std::cout &lt;&lt; source &lt;&lt; std::endl;
	for(int x = 0; x &lt; tokens.size(); x++)
	{
		std::cout &lt;&lt; tokens[x] &lt;&lt; std::endl;
	}

	std::cout &lt;&lt; std::endl;

	source = &quot;This.string.will; be tokenized, with  spaces and :puncutation!&quot;;
	tokens = TokenizeString(source, &quot;,. :;!&quot;);
	std::cout &lt;&lt; source &lt;&lt; std::endl;
	for(int x = 0; x &lt; tokens.size(); x++)
	{
		std::cout &lt;&lt; tokens[x] &lt;&lt; std::endl;
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1812084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812084</guid><dc:creator><![CDATA[jesus was black]]></dc:creator><pubDate>Mon, 23 Nov 2009 04:57:16 GMT</pubDate></item></channel></rss>