<?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[Schlüßelwort in txt finden]]></title><description><![CDATA[<p>Hallo,<br />
Ich habe folgendes Problem:</p>
<p>Ich habe eine Datei(.txt), die wie folgt aufgebaut sein kann:</p>
<pre><code>Name: &quot;Max Mustermann&quot;
Alter: &quot;18&quot;
...
...
</code></pre>
<p>Nun will ich Schlüsselwörter wie &quot;Name&quot; oder &quot;Alter&quot; darin suchen und die Infos dahinter &quot;verwenden&quot;.</p>
<p>Zum Beispiel so:<br />
<strong>Pseudocode:</strong></p>
<pre><code>If (name==&quot;Max Mustermann&quot;)
{
   mache .....
}
</code></pre>
<p>Ich danke für jede Hilfe <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/287111/schlüßelwort-in-txt-finden</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 14:40:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/287111.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 May 2011 00:01:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 00:01:08 GMT]]></title><description><![CDATA[<p>Hallo,<br />
Ich habe folgendes Problem:</p>
<p>Ich habe eine Datei(.txt), die wie folgt aufgebaut sein kann:</p>
<pre><code>Name: &quot;Max Mustermann&quot;
Alter: &quot;18&quot;
...
...
</code></pre>
<p>Nun will ich Schlüsselwörter wie &quot;Name&quot; oder &quot;Alter&quot; darin suchen und die Infos dahinter &quot;verwenden&quot;.</p>
<p>Zum Beispiel so:<br />
<strong>Pseudocode:</strong></p>
<pre><code>If (name==&quot;Max Mustermann&quot;)
{
   mache .....
}
</code></pre>
<p>Ich danke für jede Hilfe <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/2067293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067293</guid><dc:creator><![CDATA[DrunkenMastered]]></dc:creator><pubDate>Mon, 23 May 2011 00:01:08 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 04:23:33 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>nimm einfach das JSON Format <a href="http://de.wikipedia.org/wiki/JSON" rel="nofollow">http://de.wikipedia.org/wiki/JSON</a> und nutz eine der Bibliotheken für C/C++ von der Seite <a href="http://www.json.org" rel="nofollow">www.json.org</a>. Das wäre die einfachste Lösung für eine solche Klartext-Datenhaltung.<br />
Sonst müsstest du halt einen eigenen Parser schreiben (für Lernzwecke nicht schlecht) oder eben mit den guten alten sequentiellen Dateien arbeiten (schlage dies in einem C++ Buch nach).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067300</guid><dc:creator><![CDATA[shadow]]></dc:creator><pubDate>Mon, 23 May 2011 04:23:33 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 06:48:18 GMT]]></title><description><![CDATA[<p>Und hast du auch eine Frage?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067312</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 23 May 2011 06:48:18 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 07:25:17 GMT]]></title><description><![CDATA[<p>Drei gute Links:<br />
<a href="http://www.c-plusplus.net/forum/search" rel="nofollow">klick</a><br />
<a href="http://lmgtfy.com/?q=c%2B%2B+string+split" rel="nofollow">klick</a></p>
<p>Und lerne erstmal C++. Ich seh, du hast keine Lust, selber was zu machen. Noch einer von der Sorte: &quot;ach, kann das nicht jemand für mich machen?!&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067320</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Mon, 23 May 2011 07:25:17 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 11:03:48 GMT]]></title><description><![CDATA[<p>Meine Lösung:</p>
<pre><code class="language-cpp">std::fstream File(&quot;MyFile.txt&quot;); //File öffnen
std::string Name; //String für gefundene Daten
while(!File.eof()) //Solange das File nicht fertig ist
{
  std::string CurrentLine; //Tempöräre Variable
  std::getline(File, CurrentLine); //Zeile aus Datei holen
  if(CurrentLine.find(&quot;Name&quot;) == 0) //Wenn der Bezeichner Name am Anfang der Zeile ist
    Name = CurrentLine.substr(CurrentLine.find_first_of('\&quot;'), CurrentLine.find_last_of('\&quot;')); //betroffener Bereich kopieren
}
if(Name.empty())
{
  //Fehler: Nichts gefunden
}
</code></pre>
<p>Hier hat <code>Name</code> noch die Anführungs- und Schlusszeichen um sich aber das sollte kein Problem sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067380</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 23 May 2011 11:03:48 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 10:56:04 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Meine Lösung:</p>
<pre><code class="language-cpp">std::fstream File(&quot;MyFile.txt&quot;); //File öffnen
std::string Name; //String für gefundene Daten
while(!File.eof()) //Solange das File nicht fertig ist
{
  std::string CurrentLine; //Tempöräre Variable
  std::getline(File, CurrentLine); //Zeile aus Datei holen
  if(CurrentLine.find(&quot;Name&quot;) == 0) //Wenn der Bezeichner Name am Anfang der Zeile ist
    Name = CurrentLine.substr(CurrentLine.find_first_of('\&quot;'), CurrentLine.find_last_of('\&quot;')); //betroffener Bereich kopieren
}
if(File.empty())
{
  //Fehler: Nichts gefunden
}
</code></pre>
<p>Hier hat <code>Name</code> noch die Anführungs- und Schlusszeichen um sich aber das sollte kein Problem sein.</p>
</blockquote>
<p>1. Seit wann hat fstream eine Funktion namens empty()?<br />
2. Wieso überprüfst du nur auf EOF? Was ist mit anderen Fehlern die beim Einlesen auftreten können?<br />
3. Wieso fstream? Hier würde doch ein ifstream Objekt reichen!?</p>
<p>Lg freeG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067384</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Mon, 23 May 2011 10:56:04 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 11:07:24 GMT]]></title><description><![CDATA[<p>fr33g schrieb:</p>
<blockquote>
<p>1. Seit wann hat fstream eine Funktion namens empty()?<br />
2. Wieso überprüfst du nur auf EOF? Was ist mit anderen Fehlern die beim Einlesen auftreten können?<br />
3. Wieso fstream? Hier würde doch ein ifstream Objekt reichen!?</p>
</blockquote>
<p>1. Ups, ich wollte den <code>string</code> checken.<br />
2. Vielleicht sollte ich auch ggf. <code>std::bad_alloc</code> abfangen, wer weis ob der Speicher reicht...<br />
3. Wenn er auch etwas an der Datei ändern will, hat er es schon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067387</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 23 May 2011 11:07:24 GMT</pubDate></item><item><title><![CDATA[Reply to Schlüßelwort in txt finden on Mon, 23 May 2011 11:26:11 GMT]]></title><description><![CDATA[<p>-zu spät gepostet-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2067397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2067397</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Mon, 23 May 2011 11:26:11 GMT</pubDate></item></channel></rss>