<?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[incrementing strings]]></title><description><![CDATA[<p>Hi, ich hab eine kleine Funktion geschrieben, die einen String erhöhen soll. Leider stürzt das Prgramm immer ab, wenn es zum beispiel zz erhöhen soll. Eigentlich füge ich dafür extre ein char am anfang hinzu. Wär nett wenn sich das jemand mal anschauen könnte. Vielleicht seh ich ja nur den Wald vor lauter Bäumen nicht <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">using namespace std;
	unsigned short back = 1; //wievielte Nummer von hinten
	string firstPart, lastPart;
	char element;
	bool debug = true;

	while(1)
	{
		firstPart 	= pwd.substr(0,pwd.size()-back);
		element = (char)pwd[pwd.size()-back];
		lastPart	= pwd.substr(back+1,
		                      pwd.size()-firstPart.size()-1);

		element++;

		if( isdigit(element) or isalpha(element) )
		{
			if( debug )
			{
				cout&lt;&lt;&quot;INCREASING&quot;&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
			}

			pwd = firstPart+element+lastPart;
			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
			}
			return pwd;
		}
		else if(element &gt;= 123)
		{
			if( debug )
			{
				cout&lt;&lt;&quot;CHANGING BACK&quot;&lt;&lt;endl;
			}

			element = '0';

			pwd = firstPart+element+lastPart;
			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
				cout&lt;&lt;&quot;pwd.size(): &quot;&lt;&lt;pwd.size()&lt;&lt;endl;
			}
			if( back == pwd.size() )
			{
				pwd = string(&quot;/&quot;)+pwd;
				cout&lt;&lt;pwd&lt;&lt;endl;
			}
			back++;
		}
		else
		{
			element++;
		}
	}
	return pwd;
</code></pre>
<p>Danke <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/topic/146966/incrementing-strings</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 19:16:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/146966.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 12 May 2006 12:46:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to incrementing strings on Fri, 12 May 2006 12:46:31 GMT]]></title><description><![CDATA[<p>Hi, ich hab eine kleine Funktion geschrieben, die einen String erhöhen soll. Leider stürzt das Prgramm immer ab, wenn es zum beispiel zz erhöhen soll. Eigentlich füge ich dafür extre ein char am anfang hinzu. Wär nett wenn sich das jemand mal anschauen könnte. Vielleicht seh ich ja nur den Wald vor lauter Bäumen nicht <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">using namespace std;
	unsigned short back = 1; //wievielte Nummer von hinten
	string firstPart, lastPart;
	char element;
	bool debug = true;

	while(1)
	{
		firstPart 	= pwd.substr(0,pwd.size()-back);
		element = (char)pwd[pwd.size()-back];
		lastPart	= pwd.substr(back+1,
		                      pwd.size()-firstPart.size()-1);

		element++;

		if( isdigit(element) or isalpha(element) )
		{
			if( debug )
			{
				cout&lt;&lt;&quot;INCREASING&quot;&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
			}

			pwd = firstPart+element+lastPart;
			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
			}
			return pwd;
		}
		else if(element &gt;= 123)
		{
			if( debug )
			{
				cout&lt;&lt;&quot;CHANGING BACK&quot;&lt;&lt;endl;
			}

			element = '0';

			pwd = firstPart+element+lastPart;
			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
				cout&lt;&lt;&quot;pwd.size(): &quot;&lt;&lt;pwd.size()&lt;&lt;endl;
			}
			if( back == pwd.size() )
			{
				pwd = string(&quot;/&quot;)+pwd;
				cout&lt;&lt;pwd&lt;&lt;endl;
			}
			back++;
		}
		else
		{
			element++;
		}
	}
	return pwd;
</code></pre>
<p>Danke <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/1056432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056432</guid><dc:creator><![CDATA[MaxDemian]]></dc:creator><pubDate>Fri, 12 May 2006 12:46:31 GMT</pubDate></item><item><title><![CDATA[Reply to incrementing strings on Fri, 12 May 2006 12:57:30 GMT]]></title><description><![CDATA[<p>Wo ist hier ein zz und was ist pwd?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1056437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056437</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 12 May 2006 12:57:30 GMT</pubDate></item><item><title><![CDATA[Reply to incrementing strings on Fri, 12 May 2006 12:58:15 GMT]]></title><description><![CDATA[<p>Da sehe ich schonmal das Problem, daß Buchstaben und Zahlen nicht dicht hintereinander in der ASCII-Tabelle stehen (nach der 9 kommt ':' - den Bereich müsstest du evt. &quot;überspringen&quot;).</p>
<p>(übrigens kannst du statt dem &quot;firstpart+element+lastpart&quot;-Gebastel auch direkt im String schreiben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1056439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056439</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 12 May 2006 12:58:15 GMT</pubDate></item><item><title><![CDATA[Reply to incrementing strings on Fri, 12 May 2006 13:12:45 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/1387">@Braunstein</a><br />
sry, hab ich doch glatt vergessen zu sagen. Dies ist eine Methode einer Klasse, pwd ist ein string, welcher erhöht werden soll. Das Programm schlägt fehl, wenn pwd == &quot;zz&quot;</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10318">@CStoll</a><br />
überspring ich doch:</p>
<pre><code class="language-cpp">if(isdigit(element) or isalpha(element) { ... }
else { element++; }
</code></pre>
<p>Hab es jetzt aber folgendermaßen abgewandelt. Das Problem bleibt das gleich:</p>
<pre><code class="language-cpp">using namespace std;
	unsigned short back = 1; //wievielte Nummer von hinten
	char element = ' ';
	bool debug = true;

	while(1)
	{
		element = pwd[pwd.size() - back];

		if( isdigit(element) or isalpha(element) )
		{
			if( debug )
			{
				cout&lt;&lt;&quot;INCREASING&quot;&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
			}

			pwd[pwd.size() - back] = element;
			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
			}
			return pwd;
		}
		else if(element &gt;= 123)
		{
			if( debug )
			{
				cout&lt;&lt;&quot;CHANGING BACK&quot;&lt;&lt;endl;
			}

			element = '0';

			pwd[pwd.size() - back] = element;
			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
				cout&lt;&lt;&quot;pwd.size(): &quot;&lt;&lt;pwd.size()&lt;&lt;endl;
			}
			if( back == pwd.size() )
			{
				pwd = string(&quot;/&quot;)+pwd;
				cout&lt;&lt;pwd&lt;&lt;endl;
			}
			back++;
		}
		else
		{
			element++;
		}
	}
	return pwd;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1056447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056447</guid><dc:creator><![CDATA[MaxDemian]]></dc:creator><pubDate>Fri, 12 May 2006 13:12:45 GMT</pubDate></item><item><title><![CDATA[Reply to incrementing strings on Fri, 12 May 2006 13:49:12 GMT]]></title><description><![CDATA[<p>Bei mir stürzt hier nichts ab, wenn pwd = &quot;zz&quot; ist. Genau gesagt geht er gleich beim ersten return raus.<br />
Der Code ist aber auch etwas merkwürdig.<br />
Was soll das element++ da am Ende? Du überschreibst das doch sowieso gleich wieder.<br />
Was soll die Zuweisung im ersten if? An der Stelle steht doch schon element.<br />
Kannst du mal genau erklären was du machen willst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1056491</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056491</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 12 May 2006 13:49:12 GMT</pubDate></item><item><title><![CDATA[Reply to incrementing strings on Fri, 12 May 2006 14:32:36 GMT]]></title><description><![CDATA[<p>Ok, ich habs. Thx. Sollte folgendes machen:</p>
<pre><code class="language-cpp">using namespace std;
	unsigned short back = 1; //wievielte Nummer von hinten
	char element = ' ';
	bool debug = true;

	while(1)
	{
		//get the last char that can be changed (in the first round
		//the last char, if this is z, get the char before it
		element = pwd[pwd.size() - back];
		//and increase it
		element++;

		//if the char is a number or a letter, try to increase it
		if( isdigit(element) or isalpha(element) )
		{
			if( debug )
			{
				cout&lt;&lt;&quot;INCREASING&quot;&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
			}
			//if it was posible to increase the char, write it in
			//the string
			pwd[pwd.size() - back] = element;

			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
			}
			return pwd;
		}
		//if the char is not a valid number or letter anymore,
		//reset the char and increase back to look in the next
		//round on the char before this one
		else if(element &gt;= 123)
		{
			if( debug )
			{
				cout&lt;&lt;&quot;CHANGING BACK&quot;&lt;&lt;endl;
			}

			element = '0';

			pwd[pwd.size() - back] = element;

			if( debug )
			{
				cout&lt;&lt;&quot;pwd: &quot;&lt;&lt;pwd&lt;&lt;endl;
				cout&lt;&lt;&quot;back: &quot;&lt;&lt;back&lt;&lt;endl;
				cout&lt;&lt;&quot;pwd.size(): &quot;&lt;&lt;pwd.size()&lt;&lt;endl;
			}

			//if this char was already the first one, put an
			//aditional one in front of it
			if( back == pwd.size() )
			{
				pwd = string(&quot;/&quot;)+pwd;
				cout&lt;&lt;pwd&lt;&lt;endl;
			}

			back++;
		}
		//if the char is a char bettween the valid letters and
		//numbers, just go in the next round. Maybe there
		//it will be one
	}

	return pwd;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1056527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056527</guid><dc:creator><![CDATA[MaxDemian]]></dc:creator><pubDate>Fri, 12 May 2006 14:32:36 GMT</pubDate></item></channel></rss>