<?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[easy file parser]]></title><description><![CDATA[<p>ich habe eine datei, diefolgendermaßen aussieht:</p>
<pre><code class="language-cpp">one = 1
two = 324
three = 21
four = -15
</code></pre>
<p>diese lese ich zeilenweise in einen string-array ein:</p>
<pre><code class="language-cpp">protected:
		std::string filename;
		std::vector&lt;std::string&gt;* data;
	public:
		textfile(){
			filename = &quot;none&quot;;
			data = new std::vector&lt;std::string&gt;;
		}
		void load(std::string _filename){
			filename = _filename;
			std::string line;
			std::ifstream fin( _filename );
			while(!(fin.eof())){
				std::getline(fin, line, '\n');
				data-&gt;push_back(line);
			}
			fin.close();
		}
</code></pre>
<p>jetzt möchte ich eine funktion schreiben, die in z.b zeile 1 (also den string von zeile 1) ab dem &quot; = &quot; in einen anderen string speicher.</p>
<pre><code class="language-cpp">std::string getvar(int line_nbr){
  std::string tmp = data-&gt;at(line_nbr-1);
  return /*string ab dem &quot; = &quot;*/;
}
</code></pre>
<p>also zum beispiel soll aus &quot;one = 1&quot; &quot;1&quot; werden.</p>
<p>Als zweites wüsste ich gerne, wie ich aus einem string alle TABs und alle LERRZEICHEN lösche.</p>
<p>Danke schon mal im voraus <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/303549/easy-file-parser</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 09:16:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/303549.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 May 2012 18:56:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 18:59:22 GMT]]></title><description><![CDATA[<p>ich habe eine datei, diefolgendermaßen aussieht:</p>
<pre><code class="language-cpp">one = 1
two = 324
three = 21
four = -15
</code></pre>
<p>diese lese ich zeilenweise in einen string-array ein:</p>
<pre><code class="language-cpp">protected:
		std::string filename;
		std::vector&lt;std::string&gt;* data;
	public:
		textfile(){
			filename = &quot;none&quot;;
			data = new std::vector&lt;std::string&gt;;
		}
		void load(std::string _filename){
			filename = _filename;
			std::string line;
			std::ifstream fin( _filename );
			while(!(fin.eof())){
				std::getline(fin, line, '\n');
				data-&gt;push_back(line);
			}
			fin.close();
		}
</code></pre>
<p>jetzt möchte ich eine funktion schreiben, die in z.b zeile 1 (also den string von zeile 1) ab dem &quot; = &quot; in einen anderen string speicher.</p>
<pre><code class="language-cpp">std::string getvar(int line_nbr){
  std::string tmp = data-&gt;at(line_nbr-1);
  return /*string ab dem &quot; = &quot;*/;
}
</code></pre>
<p>also zum beispiel soll aus &quot;one = 1&quot; &quot;1&quot; werden.</p>
<p>Als zweites wüsste ich gerne, wie ich aus einem string alle TABs und alle LERRZEICHEN lösche.</p>
<p>Danke schon mal im voraus <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/2212382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212382</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 16 May 2012 18:59:22 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:06:58 GMT]]></title><description><![CDATA[<p><a href="http://cplusplus.com/reference/" rel="nofollow">http://cplusplus.com/reference/</a><br />
Hier gibt es eine Dokumentation der Standardbibliothek.<br />
Zur ersten Frage:<br />
Da solltest du dir std::string::find() und std::string::substr() anschauen.<br />
Zur zweiten Frage dürften dich std::remove_if() aus &lt;algorithm&gt; und das erase-remove-Idiom interessieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212386</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Wed, 16 May 2012 19:06:58 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:10:06 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>Als zweites wüsste ich gerne, wie ich aus einem string alle TABs und alle LERRZEICHEN lösche.</p>
</blockquote>
<pre><code class="language-cpp">int main()
{
		std::string str = &quot;  hallo \t welt \t&quot;;
		str.erase( std::remove_if(str.begin(),str.end(),std::isspace),str.end() ); // bzw. str.erase( std::remove_if(str.begin(),str.end(),static_cast&lt;int (*)(int)&gt;(std::isspace)),str.end() ); --&gt; Dass der MSVC mal Ruhe gibt.
		std::cout &lt;&lt; str;
		return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2212387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212387</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 16 May 2012 19:10:06 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:16:48 GMT]]></title><description><![CDATA[<p>das sieht schon mal gut aus, nur in welcher include liegen die funnktionen<br />
&quot;remove_if&quot; und &quot;isspace&quot;</p>
<p>PS: ich durchforste mal eben die doku</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212390</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 16 May 2012 19:16:48 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:16:25 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>das sieht schon mal gut aus, nur in welcher include liegen die funnktionen<br />
&quot;remove_if&quot; und &quot;isspace&quot;</p>
</blockquote>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;cctype&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2212391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212391</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 16 May 2012 19:16:25 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:18:40 GMT]]></title><description><![CDATA[<p>DANKE frage 2 ist hiermit erledigt, eins bin ich gerade dran, glaube aber nicht, dass ich das so verstanden hab, brächte am besten noch ne kleine erklärung <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/2212396</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212396</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 16 May 2012 19:18:40 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:21:59 GMT]]></title><description><![CDATA[<p>Musst du erstmal noch mal genauer erklären? Wieso in einen <code>string</code> speichern? Wieso kein <code>int</code> ? Willst du damit nicht rechen? Du willst also in einem <code>vector</code> jede komplette Zeile und in einem anderen nur die Ziffern, oder wie oder was?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212398</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 16 May 2012 19:21:59 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:26:10 GMT]]></title><description><![CDATA[<p>ja so ungefähr, als int brauche ich es erst später, die variablen in der textdatei könnten ja theoretisch auch wörter sein, und da es mir ersteinmal ums prinzip geht, brauche ich es ersteinmal als string</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212400</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 16 May 2012 19:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:37:31 GMT]]></title><description><![CDATA[<p>habs jetzt FAST:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;algorithm&gt; 
#include &lt;cctype&gt;
int main() 
 { 
         //std::string str = &quot;  hallo \t welt \t&quot;; 
         //str.erase( std::remove_if(str.begin(),str.end(),std::isspace),str.end() ); // bzw. str.erase( std::remove_if(str.begin(),str.end(),static_cast&lt;int (*)(int)&gt;(std::isspace)),str.end() ); --&gt; Dass der MSVC mal Ruhe gibt. 
         //std::cout &lt;&lt; str;
		 std::string s = &quot;abc=def&quot;; 
		 std::string s1 = s.substr(1, s.find('=')-1); 
		 std::string s2 = s.substr(s.find('=') + 1, s.length());
		 std::cout &lt;&lt; s &lt;&lt; &quot;\n&quot;&lt;&lt; s1 &lt;&lt; &quot;\n&quot;&lt;&lt; s2 &lt;&lt; &quot;\n&quot;;
		 getchar();
         return 0; 
 }
</code></pre>
<p>das einzige problem ist, das der erste buchstabe von s1 fehlt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212408</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 16 May 2012 19:37:31 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:40:44 GMT]]></title><description><![CDATA[<p>Du musst ja auch bei 0 anfangen und nicht bei 1...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212412</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Wed, 16 May 2012 19:40:44 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:41:49 GMT]]></title><description><![CDATA[<p>oh, danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /> flüchtigkeitsfehler <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/2212413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212413</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 16 May 2012 19:41:49 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 19:42:30 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
	ifstream file(&quot;test.txt&quot;);

	if( !file.is_open() )
	{
		cerr &lt;&lt; &quot;could not open file&quot;;
		return -1;
	}

	vector&lt;string&gt; complete_lines;
	vector&lt;string&gt; numbers;
	for(string str; getline(file,str);)
	{
		complete_lines.push_back(str);
		unsigned pos = str.find_first_of(&quot;-0123456789&quot;);
		string number = str.substr(pos);
		numbers.push_back(number);
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2212414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212414</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 16 May 2012 19:42:30 GMT</pubDate></item><item><title><![CDATA[Reply to easy file parser on Wed, 16 May 2012 21:44:36 GMT]]></title><description><![CDATA[<p>Und bitte lege den Vektor als Objekt in Deine Klasse, statt ihn dynamisch anzulegen. Also so:</p>
<pre><code class="language-cpp">class FooBar
{
  std::vector&lt;std::string&gt; data;
};
</code></pre>
<p>Dann brauchst Du ihn nicht im Konstruktor anzulegen, sondern er ist einfach nur da. Auch musst Du Dir Gedanken über Zuweisungsoperator und Kopierkonstruktor machen, wenn Du den dynamisch anlegst. Und den Destruktor darfst Du auch nicht vergessen. All das bleibt Dir erspart, wenn Du ihn einfach so als Instanz anlegst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2212443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2212443</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Wed, 16 May 2012 21:44:36 GMT</pubDate></item></channel></rss>