<?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[strtok für C++]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich versuche gerade mir eine strtok für C++ std::string selber zu coden, nur irgendwie komme ich noch nicht ganz mit den Pointer klar, was mach ich falsch?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

const string&amp; stringtok(const string&amp; source, const string&amp; splitter)
{
	static string str;
	static int start = -1, stop = -1;
	static string result;

	if (source.empty() == false)
	{
		str = source;
	}
	if (stop != -1)
	{
		start = str.find_first_not_of(splitter, stop);
	}
	else
	{
		start = str.find_first_not_of(splitter);
	}
	stop = str.find_first_of(splitter, start);
	if (start != -1 &amp;&amp; stop != -1)
	{
		result = str.substr(start, stop);
		return result;
	}
	else
	{
		return NULL;
	}
}

int main ()
{
	string last;
	string current;
	size_t found;

	do {
		// Eingabe
		cin &gt;&gt; current;
		// neuen String anhängen
		last.append(current);
		// String vor Bearbeitung ausgeben
		cout &lt;&lt; last &lt;&lt; endl;
		// String bearbeiten
		cout &lt;&lt; &quot;start:&quot; &lt;&lt; endl;
		string pch = stringtok(last, &quot;a&quot;);
		while (pch.empty() == false)
		{
			cout &lt;&lt; pch &lt;&lt; endl;
			pch = stringtok(NULL, &quot;a&quot;);
		}
		cout &lt;&lt; pch &lt;&lt; endl;
		cout &lt;&lt; &quot;ende:&quot; &lt;&lt; endl;
		// String einkürzen
		found = last.find_last_of(&quot;&amp;&quot;);
		last = last.substr(found+1);
		cout &lt;&lt; last &lt;&lt; endl;
	} while (current != &quot;&quot;);
	// used in the same order as described above:

	for (unsigned long i=0;i&lt;100000000;i++);
	return 0;
}
</code></pre>
<p>Gruß<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/237966/strtok-für-c</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 05:01:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/237966.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Apr 2009 10:48:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 10:48:20 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich versuche gerade mir eine strtok für C++ std::string selber zu coden, nur irgendwie komme ich noch nicht ganz mit den Pointer klar, was mach ich falsch?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

const string&amp; stringtok(const string&amp; source, const string&amp; splitter)
{
	static string str;
	static int start = -1, stop = -1;
	static string result;

	if (source.empty() == false)
	{
		str = source;
	}
	if (stop != -1)
	{
		start = str.find_first_not_of(splitter, stop);
	}
	else
	{
		start = str.find_first_not_of(splitter);
	}
	stop = str.find_first_of(splitter, start);
	if (start != -1 &amp;&amp; stop != -1)
	{
		result = str.substr(start, stop);
		return result;
	}
	else
	{
		return NULL;
	}
}

int main ()
{
	string last;
	string current;
	size_t found;

	do {
		// Eingabe
		cin &gt;&gt; current;
		// neuen String anhängen
		last.append(current);
		// String vor Bearbeitung ausgeben
		cout &lt;&lt; last &lt;&lt; endl;
		// String bearbeiten
		cout &lt;&lt; &quot;start:&quot; &lt;&lt; endl;
		string pch = stringtok(last, &quot;a&quot;);
		while (pch.empty() == false)
		{
			cout &lt;&lt; pch &lt;&lt; endl;
			pch = stringtok(NULL, &quot;a&quot;);
		}
		cout &lt;&lt; pch &lt;&lt; endl;
		cout &lt;&lt; &quot;ende:&quot; &lt;&lt; endl;
		// String einkürzen
		found = last.find_last_of(&quot;&amp;&quot;);
		last = last.substr(found+1);
		cout &lt;&lt; last &lt;&lt; endl;
	} while (current != &quot;&quot;);
	// used in the same order as described above:

	for (unsigned long i=0;i&lt;100000000;i++);
	return 0;
}
</code></pre>
<p>Gruß<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690775</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Sat, 04 Apr 2009 10:48:20 GMT</pubDate></item><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 13:11:31 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>hab mir jetzt folgende Funktion gebastelt, welche auch zu funktionieren scheint, währe aber trotzdem nett wenn sie nochmal jemand gegenliest und mir vielleicht einen Tip geben kann, was man verbessern kann...</p>
<pre><code>string* stringtok(string * source, const string&amp; splitter)
{
	static string str;
	static int start = -1, stop = -1;
	static string result;

	/*
	if (start != -1 &amp;&amp; stop == -1)
	{
		return NULL;
	}
	*/

	if (source != NULL)
	{
		str = source-&gt;c_str();
		start = -1;
		stop = -1;
	}
	if (stop != -1)
	{
		start = str.find_first_not_of(splitter, stop);
	}
	else
	{
		start = str.find_first_not_of(splitter);
	}
	stop = str.find_first_of(splitter, start);
	if (start != -1 &amp;&amp; stop != -1)
	{
		result = str.substr(start, stop-start);
		return &amp;result;
	}
	/* letztes Element weglassen, falls kein Stop vorhanden
	else if (start != -1 &amp;&amp; stop == -1)
	{
		result = str.substr(start);
		return &amp;result;
	}
	*/
	else
	{
		return NULL;
	}
}
</code></pre>
<p>Gruß<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690855</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Sat, 04 Apr 2009 13:11:31 GMT</pubDate></item><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 13:21:17 GMT]]></title><description><![CDATA[<p>strtok sollte man gar nicht benutzen, das ist ja wirklich ekelhaft, wenn schon, dann pack das in eine Klasse und speicher den Zustand in einem Objekt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690860</guid><dc:creator><![CDATA[Tippgeber]]></dc:creator><pubDate>Sat, 04 Apr 2009 13:21:17 GMT</pubDate></item><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 13:26:21 GMT]]></title><description><![CDATA[<p>Hehe, ich steh leider noch am Anfang daher hab ich bisher nur ne grobe Vorstellung was du meinst, aber ich benutze ja kein strtok sondern verwende mein eigenes...oder nicht?</p>
<p>Ich werd mich bemühen, dass so schnell wie möglich zu realisieren...</p>
<p>Gruß<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690863</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Sat, 04 Apr 2009 13:26:21 GMT</pubDate></item><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 15:07:33 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ein Tipp (aber nicht von nem C++ Profi):<br />
Versuch nicht, C-Funktionen in C++ nachzuprogrammieren. Funktionalität nachzubilden ist eine sehr schöne Sache, aber versuche hier Klassen, Iteratoren, usw. zu nutzen. Die Nutzung sollte auch intuitiv sein (strtok finde ich nicht intuitiv, hatte Schwierigkeiten es ineinander zu verschachteln). Nacheinander viele if-Dinger sind unschön. Ich erkenne die verschiedenen Fälle, die auftreten könnnen, nicht.</p>
<p>Wie schon Tippgeber meinte, benutz eine Klasse, indem du Zustände speicherst. Google mal ein wenig nach Implementierungen (c++ tokenizer). Schau dir auch mal an, wie die Boost-Bibliothek den Tokenizer implementiert.</p>
<p>Viel Spaß<br />
Tobias Philipp</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690904</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690904</guid><dc:creator><![CDATA[tphilipp_]]></dc:creator><pubDate>Sat, 04 Apr 2009 15:07:33 GMT</pubDate></item><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 15:30:10 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

std::vector&lt;std::string&gt; TokenizeString(const std::string&amp; str, const std::string&amp; delim)
{
    http://www.gamedev.net/community/forums/topic.asp?topic_id=381544
	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()
{
	std::string SplitIt = &quot;Split This String&quot;;
	std::vector&lt;std::string&gt; split = TokenizeString( SplitIt, &quot; &quot; );

	std::cout &lt;&lt; split[0] &lt;&lt; &quot;\n&quot;; // Split
	std::cout &lt;&lt; split[1] &lt;&lt; &quot;\n&quot;; // This
	std::cout &lt;&lt; split[2] &lt;&lt; &quot;\n&quot;; // String

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1690912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690912</guid><dc:creator><![CDATA[STL]]></dc:creator><pubDate>Sat, 04 Apr 2009 15:30:10 GMT</pubDate></item><item><title><![CDATA[Reply to strtok für C++ on Sat, 04 Apr 2009 15:34:26 GMT]]></title><description><![CDATA[<p>Oder Boost verwenden:<br />
<a href="http://www.boost.org/doc/libs/1_38_0/libs/tokenizer/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_38_0/libs/tokenizer/index.html</a></p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690914</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 04 Apr 2009 15:34:26 GMT</pubDate></item></channel></rss>