<?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[Wie kann ich comparsion Fehler&#x2F;Warnung verhindern?]]></title><description><![CDATA[<p>Diese Funktion zum erstezten der $-Zeichen verursacht bei mir immer diese Warnung:</p>
<pre><code>warning: comparison between signed and unsigned integer expressions
</code></pre>
<pre><code class="language-cpp">...
str = &quot;$Ausgabe von Irgendwo$&quot;;
	while (str.find(&quot;$&quot;) !=-1) 
	str.replace(str.find(&quot;$&quot;),1 ,&quot;&quot;)
...
</code></pre>
<p>Es wird zwar durchkompiliert aber gefällt mir so nicht! Wie kann ich das verhindern?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/177411/wie-kann-ich-comparsion-fehler-warnung-verhindern</link><generator>RSS for Node</generator><lastBuildDate>Wed, 24 Jun 2026 17:47:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/177411.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 31 Mar 2007 08:24:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 08:25:34 GMT]]></title><description><![CDATA[<p>Diese Funktion zum erstezten der $-Zeichen verursacht bei mir immer diese Warnung:</p>
<pre><code>warning: comparison between signed and unsigned integer expressions
</code></pre>
<pre><code class="language-cpp">...
str = &quot;$Ausgabe von Irgendwo$&quot;;
	while (str.find(&quot;$&quot;) !=-1) 
	str.replace(str.find(&quot;$&quot;),1 ,&quot;&quot;)
...
</code></pre>
<p>Es wird zwar durchkompiliert aber gefällt mir so nicht! Wie kann ich das verhindern?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256422</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Sat, 31 Mar 2007 08:25:34 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 08:37:28 GMT]]></title><description><![CDATA[<p>indem du mit dem richtigen Wert vergleichst:</p>
<pre><code class="language-cpp">while (str.find(&quot;$&quot;) !=string::npos) 
  str.replace(str.find(&quot;$&quot;),1 ,&quot;&quot;)
</code></pre>
<p>(zur Erklärung: string::find() liefert den Index des gefundenen Zeichens als size_t-Wert (und das ist ein unsigned-Typ). npos (die offizielle Kennung für &quot;gibt's nicht&quot;) ist zwar in der Regel als -1 definiert - aber konvertiert nach size_t.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256427</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sat, 31 Mar 2007 08:37:28 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 09:30:07 GMT]]></title><description><![CDATA[<p>dein Code ist zwar kurz aber nicht vollkommen korrekt und unperformant.</p>
<pre><code class="language-cpp">void replace_char(std::string&amp; string, const char find, const char repl)
{
	if (find == repl)
		return;

	std::string::size_type pos = string.find_first_of(find);
	while (pos != std::string::npos)
	{
		string.replace(pos, 1, 1, repl);
		pos = string.find_first_of(find, pos + 1);
	}
}
</code></pre>
<p>ersetzen ..</p>
<pre><code class="language-cpp">void delete_char(std::string&amp; string, const char find)
{
	std::string::size_type pos = string.find_first_of(find);
	while (pos != std::string::npos)
	{
		string.erase(pos, 1);
		pos = string.find_first_of(find, pos);
	}
}
</code></pre>
<p>... löschen ...</p>
<pre><code class="language-cpp">int main()
{
	std::string string_test(&quot;$Test$&quot;);
	std::cout &lt;&lt; string_test &lt;&lt; std::endl;
	replace_char(string_test, '$', '&quot;');
	std::cout &lt;&lt; string_test &lt;&lt; std::endl;
	delete_char(string_test, '&quot;');
	std::cout &lt;&lt; string_test &lt;&lt; std::endl;
	return 0;
}
</code></pre>
<p>.. nutzen. Gibt keinerlei Warnmeldungen ... und ist sauberer Code.</p>
<p><strong>Edit</strong><br />
Hab jetzt löschen reingemacht ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256430</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 31 Mar 2007 09:30:07 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 08:58:35 GMT]]></title><description><![CDATA[<p>Super danke!<br />
Funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256437</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Sat, 31 Mar 2007 08:58:35 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 09:10:59 GMT]]></title><description><![CDATA[<p>@DEvil: Er wollte die $ aber nicht durch Leerzeichen überschreiben, sondern löschen (und für deine Anwendung wäre std::replace() wohl noch kürzer ;))</p>
<p>@dixdix: Aber in einem Punkt hat DEvil recht - du mußt die Zielposition nicht doppelt berechnen (und anstatt die Teile gegen &quot;&quot; zu ersetzen, kannst du sie auch per erase() löschen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256442</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256442</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sat, 31 Mar 2007 09:10:59 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 09:37:49 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10318">@CStoll</a> Ok, aber war eigentlich eher als Beispiel zu verstehen, Trotzdem danke für den Hinweis.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256467</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Sat, 31 Mar 2007 09:37:49 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 14:21:51 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>@dixdix: Aber in einem Punkt hat DEvil recht - du mußt die Zielposition nicht doppelt berechnen (und anstatt die Teile gegen &quot;&quot; zu ersetzen, kannst du sie auch per erase() löschen).</p>
</blockquote>
<pre><code class="language-cpp">string&amp; erase( size_type index = 0, size_type num = npos );
</code></pre>
<p>Da muss ich doch nochmal nachhaken: ist die earse()-Methode dann nicht aufwändiger bzw. genauso aufwändig, da so wie ich das sehe mit erase() ein genaues Ziel verlangt wird. Insofern müsste man doch auch mehrmals berechnen, oder wie würde das aussehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256618</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Sat, 31 Mar 2007 14:21:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 15:01:31 GMT]]></title><description><![CDATA[<p>Guck doch mal meinen Beitrag an. Hab dir extra noch nen Beispiel hinzugefügt gehabt wo die Benutzung gezeigt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256669</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 31 Mar 2007 15:01:31 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich comparsion Fehler&#x2F;Warnung verhindern? on Sat, 31 Mar 2007 15:14:53 GMT]]></title><description><![CDATA[<p>Ah ja, stimmt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1256683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1256683</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Sat, 31 Mar 2007 15:14:53 GMT</pubDate></item></channel></rss>