<?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[Fehler erkennen]]></title><description><![CDATA[<pre><code class="language-cpp">cout &lt;&lt; &quot;Wort eingeben&quot; ;
cin &gt;&gt; wort;

if (wort == intel)
{cout &lt;&lt; &quot;Intel prouziert Prozessoren &quot;;}

if (wort == nvidia)
{cout &lt;&lt; &quot;nVidia stellt Grafikkarten her &quot;;}

if (wort == acer)
{cout &lt;&lt; &quot;Acer entwickelt Laptops &quot;;}

if (wort == nokia)
{cout &lt;&lt; &quot;Nokia ist einer der groeßten Handyhersteller. &quot;;}

if (wort == infeneon)
{cout &lt;&lt; &quot;Infeneon bietet Halbleiterchips an. &quot;;}
</code></pre>
<p>Oben seht ihr ein kleines Programm. Wenn z.B. <strong>Intel</strong> eintippt, zeigt es an, was in <strong>cout</strong> steht.</p>
<p>Aber wenn der User statt Intel sowas eintipppt -&gt; <strong>ihsfjhdfjhsdfhj</strong> &lt;- dann soll das programm alles anzeigen was mit <strong>i</strong> anfängt (z.B. Intel, infeneon), da das wort was der User eingegeben hat auch mit &quot; i &quot; anfängt.<br />
(Das soll wie bei Goolgle funktionieren : &quot;Meinten Sie : ......&quot;)</p>
<p>Könnt ihr das Programm so modifizieren, sodass es nach meiner Beschreibung funktioniert??</p>
<p>thx <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="🙂"
    /> <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/256933/fehler-erkennen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 23:06:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/256933.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 Dec 2009 09:21:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 09:21:47 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">cout &lt;&lt; &quot;Wort eingeben&quot; ;
cin &gt;&gt; wort;

if (wort == intel)
{cout &lt;&lt; &quot;Intel prouziert Prozessoren &quot;;}

if (wort == nvidia)
{cout &lt;&lt; &quot;nVidia stellt Grafikkarten her &quot;;}

if (wort == acer)
{cout &lt;&lt; &quot;Acer entwickelt Laptops &quot;;}

if (wort == nokia)
{cout &lt;&lt; &quot;Nokia ist einer der groeßten Handyhersteller. &quot;;}

if (wort == infeneon)
{cout &lt;&lt; &quot;Infeneon bietet Halbleiterchips an. &quot;;}
</code></pre>
<p>Oben seht ihr ein kleines Programm. Wenn z.B. <strong>Intel</strong> eintippt, zeigt es an, was in <strong>cout</strong> steht.</p>
<p>Aber wenn der User statt Intel sowas eintipppt -&gt; <strong>ihsfjhdfjhsdfhj</strong> &lt;- dann soll das programm alles anzeigen was mit <strong>i</strong> anfängt (z.B. Intel, infeneon), da das wort was der User eingegeben hat auch mit &quot; i &quot; anfängt.<br />
(Das soll wie bei Goolgle funktionieren : &quot;Meinten Sie : ......&quot;)</p>
<p>Könnt ihr das Programm so modifizieren, sodass es nach meiner Beschreibung funktioniert??</p>
<p>thx <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="🙂"
    /> <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/1825203</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825203</guid><dc:creator><![CDATA[JuNkEY_X]]></dc:creator><pubDate>Sun, 20 Dec 2009 09:21:47 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 09:44:16 GMT]]></title><description><![CDATA[<p>equal_range mit einem predicate für Teilstrings.<br />
Eingabe &quot;i&quot; -&gt; infineon, intel<br />
Eingabe &quot;inf&quot; -&gt; infineon</p>
<pre><code class="language-cpp">#include &lt;array&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

template&lt;typename Iter&gt; 
class string_match 
{
public:
	typedef Iter iterator;

	struct partial_string {
		partial_string(const std::string&amp; str):str(str){}
		std::string str;
	};

	struct partial_str_less {
		bool operator()(const std::string&amp; lhs, const std::string&amp; rhs) const {
			return lhs &lt; rhs;
		}

		bool operator()(const std::string&amp; lhs, const partial_string&amp; rhs) const {
			return lhs.substr(0,rhs.str.size()) &lt; rhs.str;
		}

		bool operator()(const partial_string&amp; lhs, const std::string&amp; rhs) const {
			return lhs.str &lt; rhs.substr(0,lhs.str.size());
		}
	};

	string_match(Iter first, Iter last);
	std::pair&lt;Iter, Iter&gt; match(const std::string&amp; match);
 private:
	Iter m_first;
	Iter m_last;
 };

template&lt;typename Iter&gt; 
string_match&lt;Iter&gt;::string_match(Iter first, Iter last):
	m_first(first),
	m_last(last)
{}

template&lt;typename Iter&gt; 
std::pair&lt;Iter, Iter&gt; string_match&lt;Iter&gt;::match(const std::string&amp; match) {
	return equal_range(m_first, m_last, partial_string(match), partial_str_less());
}

int main()
{
	using namespace std;
	typedef tr1::array&lt;string, 5&gt; arr;
	typedef arr::const_iterator Iter;
	typedef string_match&lt;Iter&gt; match;

	tr1::array&lt;string, 5&gt; dict = {
		&quot;intel&quot;, &quot;nvidia&quot;, &quot;acer&quot;, &quot;nokia&quot;, &quot;infineon&quot;};
	sort(dict.begin(),dict.end());

	match matcher(dict.begin(), dict.end());
	for(;;){
		string s;
		cout &lt;&lt; &quot;eingabe:&quot;;
		cin &gt;&gt; s;
		if (s == &quot;q&quot;) break;

		pair&lt;match::iterator, match::iterator&gt; result = 
			matcher.match(s);

		copy(result.first, result.second, 
			ostream_iterator&lt;string&gt;(cout,&quot;\n&quot;));
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1825204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825204</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sun, 20 Dec 2009 09:44:16 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 09:52:52 GMT]]></title><description><![CDATA[<p>brotbernd schrieb:</p>
<blockquote>
<p>equal_range mit einem predicate für Teilstrings.<br />
Eingabe &quot;i&quot; -&gt; infineon, intel<br />
Eingabe &quot;inf&quot; -&gt; infineon</p>
<pre><code class="language-cpp">#include &lt;array&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

template&lt;typename Iter&gt; 
class string_match 
{
public:
	typedef Iter iterator;

	struct partial_string {
		partial_string(const std::string&amp; str):str(str){}
		std::string str;
	};

	struct partial_str_less {
		bool operator()(const std::string&amp; lhs, const std::string&amp; rhs) const {
			return lhs &lt; rhs;
		}

		bool operator()(const std::string&amp; lhs, const partial_string&amp; rhs) const {
			return lhs.substr(0,rhs.str.size()) &lt; rhs.str;
		}

		bool operator()(const partial_string&amp; lhs, const std::string&amp; rhs) const {
			return lhs.str &lt; rhs.substr(0,lhs.str.size());
		}
	};
 
	string_match(Iter first, Iter last);
	std::pair&lt;Iter, Iter&gt; match(const std::string&amp; match);
 private:
	Iter m_first;
	Iter m_last;
 };

template&lt;typename Iter&gt; 
string_match&lt;Iter&gt;::string_match(Iter first, Iter last):
	m_first(first),
	m_last(last)
{}

template&lt;typename Iter&gt; 
std::pair&lt;Iter, Iter&gt; string_match&lt;Iter&gt;::match(const std::string&amp; match) {
	return equal_range(m_first, m_last, partial_string(match), partial_str_less());
}

int main()
{
	using namespace std;
	typedef tr1::array&lt;string, 5&gt; arr;
	typedef arr::const_iterator Iter;
	typedef string_match&lt;Iter&gt; match;

	tr1::array&lt;string, 5&gt; dict = {
		&quot;intel&quot;, &quot;nvidia&quot;, &quot;acer&quot;, &quot;nokia&quot;, &quot;infineon&quot;};
	sort(dict.begin(),dict.end());

	match matcher(dict.begin(), dict.end());
	for(;;){
		string s;
		cout &lt;&lt; &quot;eingabe:&quot;;
		cin &gt;&gt; s;
		if (s == &quot;q&quot;) break;

		pair&lt;match::iterator, match::iterator&gt; result = 
			matcher.match(s);

		copy(result.first, result.second, 
			ostream_iterator&lt;string&gt;(cout,&quot;\n&quot;));
	}

	return 0;
}
</code></pre>
</blockquote>
<p>wow geht es net bisl einfacher???.<br />
das programm soll ja nur den anfangsbuchstaben lesen und alles ausgeben was mit diesen buschtabe anfängt.^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1825208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825208</guid><dc:creator><![CDATA[JuNkEY_X]]></dc:creator><pubDate>Sun, 20 Dec 2009 09:52:52 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 09:59:47 GMT]]></title><description><![CDATA[<p>Das ist doch sehr einfach.<br />
Das entschiedene ist, dass du eine sortierte Range an Wörtern braucht und daran ein <a href="http://cplusplus.com/reference/algorithm/equal_range/" rel="nofollow">equal_range</a> durchführst.<br />
Wenn du nur den Anfangsbuchstaben betrachten willst musst du das predicate (partial_str_less) anpassen.</p>
<pre><code class="language-cpp">bool operator()(const std::string&amp; lhs, const std::string&amp; rhs) const {
            return lhs[0] &lt; rhs[0];
        }
</code></pre>
<p>Schau dir mal im obigen Link die Referenz zu equal_range an.<br />
Mach dich mit der STL vertraut, das ist extrem nützliches Zeugs.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1825214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825214</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sun, 20 Dec 2009 09:59:47 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 09:59:59 GMT]]></title><description><![CDATA[<p>fang doch einfach mal an.</p>
<p>ersten buchstaben der eingabe abholen und dann die daten in irgendeiner form (array, datei...) abholen und je eingabe ausgeben. so ist wohl eure aufgabe <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>
<p>wenn du nicht weiterkommst, wieder fragen.</p>
<p>:xmas2:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1825215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825215</guid><dc:creator><![CDATA[elise]]></dc:creator><pubDate>Sun, 20 Dec 2009 09:59:59 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 10:42:22 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich verstehe deine Probleme völlig mit diesen 100 Zeilen Code.</p>
<p>Ich als Anfänger (jetzt schon nen bissl weiter fortgeschritten :p) möchte auch immer den ganze Code nachvollziehen können.</p>
<p>Also hier ist eine viel einfachere Lösung, die auch bloss das macht, was du möchtest, nicht mehr.</p>
<p>Oh und bei deinen if checks sollte das so aussehen:</p>
<pre><code class="language-cpp">if (wort == &quot;blabla&quot;) // richtig
if (wort == blabla) // falsch
</code></pre>
<p>Ich würde dir vorschlagen deine Wörter in ein Array zu packen, bei der Eingabe zuerst schauen ob ein Wort, dass in deinem Array eingegeben wurde existiert, falls ja dieses ausgeben.<br />
Danach durch dein Array loopen, jeweils den ersten Buchstaben der Eingabe mit dem ersten Buchstaben deines Strings in deinem Array vergleichen, falls es übereinstimmt ausgeben:</p>
<pre><code class="language-cpp">string words[3] = {&quot;bla&quot;, &quot;ala&quot;, &quot;cala&quot;};
const int SIZE = 3;
bool isInWords = false;

cin &gt;&gt; word;

for (int i = 0; i &lt; SIZE; i++) {
  if (word == words[i]) {
     cout &lt;&lt; words[i] &lt;&lt; endl;
     isInWords = true;
     break;
  }
}

if (!isInWords) { // Falls kein Wort mit der Eingabe übereinstimmt
  for (int i = 0; i &lt; SIZE; i++) {
    if (word[0] == words[i][0]) { // Falls die ersten Buchstaben übereinstimmen..
      cout &lt;&lt; words[i] &lt;&lt; endl;
    }
  }
}
</code></pre>
<p>Es ist ungetestet, also falls was nicht funktioniert tuts mir leid <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1825229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825229</guid><dc:creator><![CDATA[Samyboy]]></dc:creator><pubDate>Sun, 20 Dec 2009 10:42:22 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 11:01:07 GMT]]></title><description><![CDATA[<p>Samyboy schrieb:</p>
<blockquote>
<pre><code class="language-cpp">for (int i = 0; i &lt; SIZE; i++) {
</code></pre>
</blockquote>
<p>Was machst du wenn SIZE die Größe des Dudens ist? Möchtest du wirklich jedes Wort einzeln durchgehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1825239</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825239</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sun, 20 Dec 2009 11:01:07 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 11:04:00 GMT]]></title><description><![CDATA[<p>brotbernd schrieb:</p>
<blockquote>
<p>Samyboy schrieb:</p>
<blockquote>
<pre><code class="language-cpp">for (int i = 0; i &lt; SIZE; i++) {
</code></pre>
</blockquote>
<p>Was machst du wenn SIZE die Größe des Dudens ist? Möchtest du wirklich jedes Wort einzeln durchgehen?</p>
</blockquote>
<p>Nein, dann würde ich das ganze natürlich nicht so machen.</p>
<p>Aber es ist offentsichtlich, dass Er/Sie noch ein Anfänger ist, daher möchte ich Ihn/Sie nicht mit Code bombadieren, denn wenn man das bei mir anfangs tat, verlor ich sofort die Lust und Motivation <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/1825243</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825243</guid><dc:creator><![CDATA[Samyboy]]></dc:creator><pubDate>Sun, 20 Dec 2009 11:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler erkennen on Sun, 20 Dec 2009 11:18:41 GMT]]></title><description><![CDATA[<p>Das ist halt eine generische Lösung die ich so aus der Kiste gezaubert habe.<br />
Aber weil heute der 4.Advent :xmas1: ist eine Reduzierung aufs Wesentliche für unmotivierte Anfänger <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>
<pre><code class="language-cpp">bool str_less(const std::string&amp; lh, const std::string&amp; rh)
{
        // Anfangsbuchstabe ist kleiner
	return lh[0] &lt; rh[0];
}

int main()
{
	using namespace std;
	typedef tr1::array&lt;string, 5&gt; Wortarray;
	typedef Wortarray::const_iterator Iter;

	// Array von bekannten Wörtern
	Wortarray dict = {
        &quot;intel&quot;, &quot;nvidia&quot;, &quot;acer&quot;, &quot;nokia&quot;, &quot;infineon&quot;}; 
	// Wörter sortieren
	sort(dict.begin(), dict.end());

	for(;;){
		// Suchwort eingeben
		string s;
		cout &lt;&lt; &quot;eingabe:&quot;;
		cin &gt;&gt; s;
		if (s == &quot;q&quot;) break;

		// Wörter suchen mit str_less
		pair&lt;Iter,Iter&gt; result = 
			equal_range(dict.begin(), dict.end(), s, &amp;str_less);

		// Nach cout kopieren
		copy(result.first, result.second, 
			ostream_iterator&lt;string&gt;(cout, &quot;\n&quot;));
	}

	return 0;
}
</code></pre>
<p>Achtung: Leere Strings werden in str_less nicht abgefangen.<br />
Wenn etwas unklar ist nicht aufgeben sondern fragen <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/1825248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1825248</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sun, 20 Dec 2009 11:18:41 GMT</pubDate></item></channel></rss>