<?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[String auf int untersuchen]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich habe hier mal 2 Versionen. Die erste hat mir immer gut geholfen.<br />
Ich schätze in C++ sollte man aber auf die 2. Variante zurückgreifen.<br />
Jedoch brauch ich da mal ein paar Tipps, wie man die Fehlerbehandlung richtig macht. So wie es jetzt ist, funktioniert es zwar, aber gefallen tut mit das nicht.</p>
<pre><code>std::string buffer;
	int dummy;  
	POS pbuff;

	// Reading X Axis   using 'old' sscanf
	std::cout &lt;&lt; &quot;\nEnter X : &quot;;

	int rv = 0;
	do{ 		
		getline(std::cin, buffer);	
	    rv = sscanf(buffer.c_str(), &quot;%d&quot;, &amp;dummy);   //ich könnte hier gleich pbuff.X nehmen, mehr dazu in Frage 2
	}while( rv != 1);

	pbuff.X = dummy;

	// Reading Y Axis using stringstream

	std::cout &lt;&lt; &quot;\nEnter Y : &quot;; 

	int chk;  
	do{
		chk = 0;
		getline(std::cin, buffer);
		std::stringstream input_scan(buffer) ; 

		if (! (input_scan &gt;&gt; pbuff.Y) ){
		    chk = 1;
		}

	}while( chk == 1 );
</code></pre>
<p>Dann habe ich noch eine Frage, bzgl . der push_back funktion bei Vektoren:</p>
<p>Sieht jetzt ungefähr so aus</p>
<p>main.cpp:</p>
<pre><code>std::vector&lt;POS&gt; PRG_1;   // Pos ist ne struct von mir die X, Y , Z als int enthält

fill(PRG_1);
</code></pre>
<p>dazu fill.cpp:</p>
<pre><code>void fill(std::vector&lt;POS&gt; &amp;myVec){

	POS dummy;
	char c;
	int chk;
	const int ignore_size = 256;

	do{

	chk = 0;
	std::cout &lt;&lt; &quot;Enter new Point ? &lt; y / n &gt; &quot;;
	std::cin &gt;&gt; c;
	std::cin.ignore(ignore_size, '\n');

	   switch (c){

	   	case 'y'   : dummy = fill(); 
		   	 	     myVec.push_back(dummy); 
		   	 	     chk = 1;
					 break;

	   	case 'n'   : std::cout &lt;&lt; &quot;\nBye\n&quot; ; break;  
	   	default    : std::cout &lt;&lt; &quot;\nsth. went wrong...&quot;;  chk = 1;  break;	
	   }

   }while (chk == 1);
</code></pre>
<p>und fill.cpp:</p>
<pre><code>POS fill(){

	 // code aus erstem Beispiel

	// Reading X Axis   using 'old' sscanf
	 	return pbuff;

} // End Fill
</code></pre>
<p>Die Frage nun, für die Push_Back &quot;funktion&quot; brauche ich immer einen Dummy oder? Also ich muss meine Werte erst mal irgendwo rein speichern und kann diese dann mit push_back in den Vektor bringen. Ohne Zwischenspeichern geht nicht oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328256/string-auf-int-untersuchen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 03:37:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328256.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Sep 2014 10:29:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String auf int untersuchen on Tue, 30 Sep 2014 10:29:44 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich habe hier mal 2 Versionen. Die erste hat mir immer gut geholfen.<br />
Ich schätze in C++ sollte man aber auf die 2. Variante zurückgreifen.<br />
Jedoch brauch ich da mal ein paar Tipps, wie man die Fehlerbehandlung richtig macht. So wie es jetzt ist, funktioniert es zwar, aber gefallen tut mit das nicht.</p>
<pre><code>std::string buffer;
	int dummy;  
	POS pbuff;

	// Reading X Axis   using 'old' sscanf
	std::cout &lt;&lt; &quot;\nEnter X : &quot;;

	int rv = 0;
	do{ 		
		getline(std::cin, buffer);	
	    rv = sscanf(buffer.c_str(), &quot;%d&quot;, &amp;dummy);   //ich könnte hier gleich pbuff.X nehmen, mehr dazu in Frage 2
	}while( rv != 1);

	pbuff.X = dummy;

	// Reading Y Axis using stringstream

	std::cout &lt;&lt; &quot;\nEnter Y : &quot;; 

	int chk;  
	do{
		chk = 0;
		getline(std::cin, buffer);
		std::stringstream input_scan(buffer) ; 

		if (! (input_scan &gt;&gt; pbuff.Y) ){
		    chk = 1;
		}

	}while( chk == 1 );
</code></pre>
<p>Dann habe ich noch eine Frage, bzgl . der push_back funktion bei Vektoren:</p>
<p>Sieht jetzt ungefähr so aus</p>
<p>main.cpp:</p>
<pre><code>std::vector&lt;POS&gt; PRG_1;   // Pos ist ne struct von mir die X, Y , Z als int enthält

fill(PRG_1);
</code></pre>
<p>dazu fill.cpp:</p>
<pre><code>void fill(std::vector&lt;POS&gt; &amp;myVec){

	POS dummy;
	char c;
	int chk;
	const int ignore_size = 256;

	do{

	chk = 0;
	std::cout &lt;&lt; &quot;Enter new Point ? &lt; y / n &gt; &quot;;
	std::cin &gt;&gt; c;
	std::cin.ignore(ignore_size, '\n');

	   switch (c){

	   	case 'y'   : dummy = fill(); 
		   	 	     myVec.push_back(dummy); 
		   	 	     chk = 1;
					 break;

	   	case 'n'   : std::cout &lt;&lt; &quot;\nBye\n&quot; ; break;  
	   	default    : std::cout &lt;&lt; &quot;\nsth. went wrong...&quot;;  chk = 1;  break;	
	   }

   }while (chk == 1);
</code></pre>
<p>und fill.cpp:</p>
<pre><code>POS fill(){

	 // code aus erstem Beispiel

	// Reading X Axis   using 'old' sscanf
	 	return pbuff;

} // End Fill
</code></pre>
<p>Die Frage nun, für die Push_Back &quot;funktion&quot; brauche ich immer einen Dummy oder? Also ich muss meine Werte erst mal irgendwo rein speichern und kann diese dann mit push_back in den Vektor bringen. Ohne Zwischenspeichern geht nicht oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420019</guid><dc:creator><![CDATA[beg_offl]]></dc:creator><pubDate>Tue, 30 Sep 2014 10:29:44 GMT</pubDate></item><item><title><![CDATA[Reply to String auf int untersuchen on Tue, 30 Sep 2014 10:34:05 GMT]]></title><description><![CDATA[<p>Statt</p>
<pre><code>dummy = fill();
myVec.push_back(dummy);
</code></pre>
<p>kannste auch schreiben</p>
<pre><code>myVec.push_back(fill());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420021</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 30 Sep 2014 10:34:05 GMT</pubDate></item><item><title><![CDATA[Reply to String auf int untersuchen on Tue, 30 Sep 2014 12:05:55 GMT]]></title><description><![CDATA[<p>Ok, da ich ja nen Return Wert habe. Ansonsten muss ich also erstmal wo speichern und dann push_back ´en.</p>
<p>Wie schaut´s mit den stringstream aus? Kann man das so lassen oder prüft man da irgendwie mit ???.fail() oder so ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420033</guid><dc:creator><![CDATA[beg___]]></dc:creator><pubDate>Tue, 30 Sep 2014 12:05:55 GMT</pubDate></item></channel></rss>