<?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[problem mit bool variable]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Hab das Problem, dass die boolsches Variable b immer auf false gesetzt wird.<br />
Kann mir bitte wer helfen.<br />
Hab die Variable als true deklariert und sie soll sich nur änderen, wenn in der FOR Schleife eine IF Bedingung erfüllt ist. Aber das geht irgendwie nicht.</p>
<p>Danke für Hinweise.</p>
<p>Johannes</p>
<pre><code class="language-cpp">#include &lt;fstream&gt; 
#include &lt;iostream&gt; 
#include &lt;vector&gt; 
#include &lt;string&gt; 

using namespace std; 
int main(int argc, char **argv)

 { 
  string str; 
  fstream f;
  string dateiname;
  vector&lt;string&gt; vec;
  string output;

  string C=&quot; &quot;;
  string S=&quot; &quot;;
  string L=&quot; &quot;;

  string data;          

        long int a=0;  
        int ii=0;
        int i=0;
        long int add=0;
        bool b = true;

        int c=0;

// Variablen für Berechnung
char* StopPosition = 0;

  cout &lt;&lt; &quot;******************************************************&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*    TEXTFILTER PROGRAMM -        Johannes JAN 2006  *&quot;&lt;&lt;endl;

  cout &lt;&lt; &quot;******************************************************&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*      Bitte zu oeffnende Datei mit PFAD eingeben    *&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*      PFAD unbeding mit \\ angeben!                 *&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*      Bsp.: C:\\dateien\\filename                   *&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;******************************************************&quot;&lt;&lt;endl;

getline(cin, dateiname); 
ifstream ifs(dateiname.c_str());

while (!ifs.eof()) {  // Einlesen der DATEI
getline(ifs, str);                     // Datei wird Zeile in Vector vec
vec.push_back(str);                     // Zeile wird an Vektor 
a++;  

}

   	f.open(&quot;c:\\out30.csv&quot;,ios::out); 

	for(ii=0;ii&lt;=15;++ii) 

	{ 
	  cout &lt;&lt; vec[ii].substr(111,1) &lt;&lt; endl;

            if (vec[ii].substr(111,1)==&quot;C&quot;)

            {            
            C=vec[ii].substr(24,52);
            C+=&quot;;&quot;; 
			b=false;
			cout &lt;&lt; &quot;C erkannt &quot;&lt;&lt;endl; 	                      
            }

            if (vec[ii].substr(111,1)==&quot;S&quot;)

            {
            S=vec[ii].substr(24,52);
            S+=&quot;;&quot;; 
	   b=false;
	   cout &lt;&lt; &quot;S erkannt &quot;&lt;&lt;endl;	                            
            }

            if (vec[ii].substr(111,1)==&quot;L&quot;)   
            {
            L=vec[ii].substr(24,52);
            L+=&quot;;&quot;; 	
	   b=false;
	   cout &lt;&lt; &quot;L erkannt &quot;&lt;&lt;endl;	 	                         
            }

            cout &lt;&lt; b &lt;&lt; endl;	// Wie kann es sein, dass b immer false ist
                                     // ? Was mache ich da falsch    

		if (b==true) 

        {
         // ... langer Anweisungsblock
			}
	f &lt;&lt; vec[ii] &lt;&lt; endl; 
} 

if (!f)

{
cout &lt;&lt; &quot;Die Ausgabe in die Datei hat nicht funktioniert&quot; &lt;&lt; endl;
}

else

{    
f.close();
cout &lt;&lt;&quot;Datei erzeugt!&quot; &lt;&lt;endl;   
}

cin &gt;&gt; a;

};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/133406/problem-mit-bool-variable</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 21:44:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/133406.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Jan 2006 14:21:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 14:21:00 GMT]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Hab das Problem, dass die boolsches Variable b immer auf false gesetzt wird.<br />
Kann mir bitte wer helfen.<br />
Hab die Variable als true deklariert und sie soll sich nur änderen, wenn in der FOR Schleife eine IF Bedingung erfüllt ist. Aber das geht irgendwie nicht.</p>
<p>Danke für Hinweise.</p>
<p>Johannes</p>
<pre><code class="language-cpp">#include &lt;fstream&gt; 
#include &lt;iostream&gt; 
#include &lt;vector&gt; 
#include &lt;string&gt; 

using namespace std; 
int main(int argc, char **argv)

 { 
  string str; 
  fstream f;
  string dateiname;
  vector&lt;string&gt; vec;
  string output;

  string C=&quot; &quot;;
  string S=&quot; &quot;;
  string L=&quot; &quot;;

  string data;          

        long int a=0;  
        int ii=0;
        int i=0;
        long int add=0;
        bool b = true;

        int c=0;

// Variablen für Berechnung
char* StopPosition = 0;

  cout &lt;&lt; &quot;******************************************************&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*    TEXTFILTER PROGRAMM -        Johannes JAN 2006  *&quot;&lt;&lt;endl;

  cout &lt;&lt; &quot;******************************************************&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*      Bitte zu oeffnende Datei mit PFAD eingeben    *&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*      PFAD unbeding mit \\ angeben!                 *&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;*      Bsp.: C:\\dateien\\filename                   *&quot;&lt;&lt;endl;
  cout &lt;&lt; &quot;******************************************************&quot;&lt;&lt;endl;

getline(cin, dateiname); 
ifstream ifs(dateiname.c_str());

while (!ifs.eof()) {  // Einlesen der DATEI
getline(ifs, str);                     // Datei wird Zeile in Vector vec
vec.push_back(str);                     // Zeile wird an Vektor 
a++;  

}

   	f.open(&quot;c:\\out30.csv&quot;,ios::out); 

	for(ii=0;ii&lt;=15;++ii) 

	{ 
	  cout &lt;&lt; vec[ii].substr(111,1) &lt;&lt; endl;

            if (vec[ii].substr(111,1)==&quot;C&quot;)

            {            
            C=vec[ii].substr(24,52);
            C+=&quot;;&quot;; 
			b=false;
			cout &lt;&lt; &quot;C erkannt &quot;&lt;&lt;endl; 	                      
            }

            if (vec[ii].substr(111,1)==&quot;S&quot;)

            {
            S=vec[ii].substr(24,52);
            S+=&quot;;&quot;; 
	   b=false;
	   cout &lt;&lt; &quot;S erkannt &quot;&lt;&lt;endl;	                            
            }

            if (vec[ii].substr(111,1)==&quot;L&quot;)   
            {
            L=vec[ii].substr(24,52);
            L+=&quot;;&quot;; 	
	   b=false;
	   cout &lt;&lt; &quot;L erkannt &quot;&lt;&lt;endl;	 	                         
            }

            cout &lt;&lt; b &lt;&lt; endl;	// Wie kann es sein, dass b immer false ist
                                     // ? Was mache ich da falsch    

		if (b==true) 

        {
         // ... langer Anweisungsblock
			}
	f &lt;&lt; vec[ii] &lt;&lt; endl; 
} 

if (!f)

{
cout &lt;&lt; &quot;Die Ausgabe in die Datei hat nicht funktioniert&quot; &lt;&lt; endl;
}

else

{    
f.close();
cout &lt;&lt;&quot;Datei erzeugt!&quot; &lt;&lt;endl;   
}

cin &gt;&gt; a;

};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/968948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/968948</guid><dc:creator><![CDATA[keboo]]></dc:creator><pubDate>Tue, 17 Jan 2006 14:21:00 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 14:26:34 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Wann wird die Variable den auf false gesetzt. Du machst es in deinem Code doch selber. Wo soll es denn true sein?</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/968953</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/968953</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 17 Jan 2006 14:26:34 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 14:34:23 GMT]]></title><description><![CDATA[<p>hi!</p>
<p>sorry, ahbe mich anscheinend zu unklar ausgedrückt.</p>
<p>Für den Anweisungsblock</p>
<pre><code class="language-cpp">if (b==true) 

        {
         // ... langer Anweisungsblock
            }
</code></pre>
<p>soll b true sein. Das soll dann passieren, wenn der einstellige Substring</p>
<p>vec[ii].substr(111,1) weder C, L oder S als Sting enthält.<br />
Die oben angeführte if Schleife wird aber nie angesprochen, da b immer auf false gestellt wird, auch wenn der Substring keine der 3 gesuchten Buchstaben enthält.</p>
<p>Danke,</p>
<p>Johannes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/968960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/968960</guid><dc:creator><![CDATA[keboo]]></dc:creator><pubDate>Tue, 17 Jan 2006 14:34:23 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 14:39:35 GMT]]></title><description><![CDATA[<p>Ich vermute mal (so ganz ins blaue), dass b einfach false bleibt, nachdem sie einmal auf false gesetzt wurde. Du solltest Dich also nicht fragen warum b false wird, sondern warum b false bleibt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/968968</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/968968</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 17 Jan 2006 14:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 14:44:15 GMT]]></title><description><![CDATA[<p>Danke!</p>
<p>Das wars!<br />
Oft liegen die Fehler in den einfachen Sachen!</p>
<p>Danke!</p>
<p>johannes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/968974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/968974</guid><dc:creator><![CDATA[keboo]]></dc:creator><pubDate>Tue, 17 Jan 2006 14:44:15 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 15:55:41 GMT]]></title><description><![CDATA[<p>If( b == true ) ist redundant, da der Ausdruck auf true oder false ausgewertet wird, somit prüfst du zuerst ob b == true und das Ergebnis dieses Vergleiches wird von dem If auf true oder false abgeprüft. If( b ) genügt vollkommen, hier wird der Ausdruck, in dem Fall die Variable b, auf true oder false abgeprüft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969070</guid><dc:creator><![CDATA[Any]]></dc:creator><pubDate>Tue, 17 Jan 2006 15:55:41 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 16:00:47 GMT]]></title><description><![CDATA[<p>Any schrieb:</p>
<blockquote>
<p>If( b == true ) ist redundant,...</p>
</blockquote>
<p>Es gibt Leute die das als &quot;besser lesbar&quot; bezeichnen. Ich übrigens nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969075</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 17 Jan 2006 16:00:47 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit bool variable on Tue, 17 Jan 2006 17:28:22 GMT]]></title><description><![CDATA[<p>Any schrieb:</p>
<blockquote>
<p>If( b == true ) ist redundant, da der Ausdruck auf true oder false ausgewertet wird, somit prüfst du zuerst ob b == true und das Ergebnis dieses Vergleiches wird von dem If auf true oder false abgeprüft. If( b ) genügt vollkommen, hier wird der Ausdruck, in dem Fall die Variable b, auf true oder false abgeprüft.</p>
</blockquote>
<p>Es gibt auch den Kompiler der das wegoptimiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969142</guid><dc:creator><![CDATA[moe szyslak]]></dc:creator><pubDate>Tue, 17 Jan 2006 17:28:22 GMT</pubDate></item></channel></rss>