<?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[strings mit Leerzeichen]]></title><description><![CDATA[<p>Hallo!<br />
Ich weiss, das wurde schon mehrfach besprochen, aber ich finde hier keine<br />
Lösung für meinen speziellen Fall.<br />
Ich lese aus einer Datei einen String aus, der auch Leerzeichen enthalten<br />
kann.</p>
<pre><code class="language-cpp">//Open projectfile 
         ProjectFile.open(_FileName.c_str(),ios_base::in); 
         if(!ProjectFile) 
         { 
             return LOAD_ERROR; 
         } 

         //Read data from projectfile and write it to the musiclist and bomblist 
         BombList-&gt;clear(); 
         ProjectFile&gt;&gt;size; 
         for(int i=1;i!=size;i++) 
         { 
             ProjectFile&gt;&gt;tempBombId&gt;&gt;tempBombLaunchTime&gt;&gt;tempBombLaunchGroup&gt;&gt;tempBombLaunchSlot; 
             editBombs(ADD,tempBombId,tempBombLaunchTime,tempBombLaunchGroup,tempBombLaunchSlot,i,0); 
         } 

         ProjectFile.close();
</code></pre>
<p>Mit den &gt;&gt;-Operatoren komm ich hier nicht weiter, wegen der Leerzeichen.<br />
Funktionieren Leerzeichen in Strings generell nicht, oder liegt das nur<br />
an den &gt;&gt;-Operatoren?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/154243/strings-mit-leerzeichen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 02:27:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/154243.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Jul 2006 15:00:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to strings mit Leerzeichen on Tue, 25 Jul 2006 15:00:20 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Ich weiss, das wurde schon mehrfach besprochen, aber ich finde hier keine<br />
Lösung für meinen speziellen Fall.<br />
Ich lese aus einer Datei einen String aus, der auch Leerzeichen enthalten<br />
kann.</p>
<pre><code class="language-cpp">//Open projectfile 
         ProjectFile.open(_FileName.c_str(),ios_base::in); 
         if(!ProjectFile) 
         { 
             return LOAD_ERROR; 
         } 

         //Read data from projectfile and write it to the musiclist and bomblist 
         BombList-&gt;clear(); 
         ProjectFile&gt;&gt;size; 
         for(int i=1;i!=size;i++) 
         { 
             ProjectFile&gt;&gt;tempBombId&gt;&gt;tempBombLaunchTime&gt;&gt;tempBombLaunchGroup&gt;&gt;tempBombLaunchSlot; 
             editBombs(ADD,tempBombId,tempBombLaunchTime,tempBombLaunchGroup,tempBombLaunchSlot,i,0); 
         } 

         ProjectFile.close();
</code></pre>
<p>Mit den &gt;&gt;-Operatoren komm ich hier nicht weiter, wegen der Leerzeichen.<br />
Funktionieren Leerzeichen in Strings generell nicht, oder liegt das nur<br />
an den &gt;&gt;-Operatoren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103926</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Tue, 25 Jul 2006 15:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Tue, 25 Jul 2006 15:11:55 GMT]]></title><description><![CDATA[<p>Wie sind denn die Daten in Deiner Datei getrennt, wenn nicht durch Leerzeichen? Schau Dir evtl. mal die Funktion 'getline' an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103932</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Tue, 25 Jul 2006 15:11:55 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Tue, 25 Jul 2006 15:33:48 GMT]]></title><description><![CDATA[<p>Die sind durch newline getrennt.<br />
Mit getline() kam dasselbe raus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103944</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Tue, 25 Jul 2006 15:33:48 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Tue, 25 Jul 2006 15:41:24 GMT]]></title><description><![CDATA[<p>Wie schreibst du deine Daten denn raus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103948</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Tue, 25 Jul 2006 15:41:24 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Tue, 25 Jul 2006 15:45:35 GMT]]></title><description><![CDATA[<p>mase schrieb:</p>
<blockquote>
<p>Die sind durch newline getrennt.<br />
Mit getline() kam dasselbe raus.</p>
</blockquote>
<p>'getline' sollte wunderbar funktionieren. Wenn bei Dir etwas anderes rauskam, dann stimmt das Trennzeichen nicht.</p>
<pre><code class="language-cpp">std::fstream ProjectFile(&quot;C:\\test1&quot;);

if (!ProjectFile) throw &quot;Unable to open the file.&quot;;

std::string line1, line2, line3;

getline(ProjectFile, line1);
getline(ProjectFile, line2);
getline(ProjectFile, line3);

std::cout &lt;&lt; line1 &lt;&lt; &quot;;&quot; &lt;&lt; line2 &lt;&lt; &quot;;&quot; &lt;&lt; line3 &lt;&lt; &quot;;&quot; &lt;&lt; std::endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1103951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103951</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Tue, 25 Jul 2006 15:45:35 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Tue, 25 Jul 2006 19:30:48 GMT]]></title><description><![CDATA[<p>@mase: Wieso machst du es nicht so wie ich es dir in dem anderen Thread geschrieben habe ??ß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104129</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 25 Jul 2006 19:30:48 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 15:21:44 GMT]]></title><description><![CDATA[<p>@Freak_Coder<br />
Das Speichern und Laden funktioniert ja jetzt, nur halt noch das Problem<br />
mit den Leerzeichen.<br />
getline() wird wohl das Zauberwort sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104708</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 15:21:44 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 15:44:50 GMT]]></title><description><![CDATA[<p>Ich hab versucht, den getline() mit dem Operator &gt;&gt; zu mischen.<br />
Das scheint nicht zu gehen.</p>
<pre><code class="language-cpp">getline(ProjectFile,tempMusicFile);
        ProjectFile&gt;&gt;tempMusicInpoint&gt;&gt;tempMusicOutpoint&gt;&gt;tempGap;
        tempMusicGap=static_cast&lt;Gap&gt;(tempGap);
</code></pre>
<p>Wenn ich alles mit getline() auslese, dann hab ich das Problem, dass ich<br />
strings in uints umwandeln muss, was mit static_cast nicht funktioniert.<br />
Im File ist jeweils nur der erste Eintrag ein string, der Leerzeichen<br />
enthalten kann. Alle weiteren sind uints.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104723</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 15:44:50 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 16:05:06 GMT]]></title><description><![CDATA[<p>Das Problem liess sich mit atoi() lösen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104737</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104737</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:05:06 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 16:18:21 GMT]]></title><description><![CDATA[<p>Nur als Hinweis den Link zum FAQ Thema <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39488.html" rel="nofollow">einmal Zahl nach String und zurück</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104761</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:18:21 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 16:47:29 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">getline(ProjectFile,tempBombId);
        getline(ProjectFile,temp1);
        getline(ProjectFile,temp2);
        getline(ProjectFile,temp3);
        tempBombLaunchTime=atoi(temp1.c_str());
        tempBombLaunchGroup=atoi(temp2.c_str());
        tempBombLaunchSlot=atoi(temp3.c_str());
</code></pre>
<p>So konnte ich meine Datei auslesen.<br />
Nur beim Schreiben hab ich Probleme.<br />
Mit ultoa() wollte ich meine uints in strings umwandeln.</p>
<pre><code class="language-cpp">ultoa(MusicIter-&gt;getMusicInpoint(),temp1,10);
        ultoa(MusicIter-&gt;getMusicOutpoint(),temp2,10);
        ultoa(static_cast&lt;unsigned int&gt;(MusicIter-&gt;getMusicGap()),temp3(),10);
        getline(temp1.,ProjectFile);
        getline(temp2,ProjectFile);
        getline(temp3,ProjectFile);
</code></pre>
<p>Doch das funktioniert nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104785</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:47:29 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 16:55:35 GMT]]></title><description><![CDATA[<p>Also nochmal von vorne...</p>
<p>Erstmal speicherst du deine Daten so ab:</p>
<pre><code class="language-cpp">for(BombIter=BombList-&gt;begin();BombIter!=BombList-&gt;end();++BombIter)
{
ProjectFile &lt;&lt;BombIter-&gt;getBombId() &lt;&lt; &quot; &quot; &lt;&lt;BombIter-&gt;getBombLaunchTime()
       &lt;&lt;&quot; &quot; &lt;&lt;BombIter-&gt;getBombLaunchGroup() &lt;&lt;&quot; &quot;
       &lt;&lt;&quot; &quot; &lt;&lt;BombIter-&gt;getBombLaunchSlot() &lt;&lt;endl;
}
</code></pre>
<p>Dann sieht deine Datei so aus:</p>
<pre><code>&lt;String&gt; &lt;uint&gt; &lt;uint&gt; &lt;uint&gt;
&lt;String&gt; &lt;uint&gt; &lt;uint&gt; &lt;uint&gt;
&lt;String&gt; &lt;uint&gt; &lt;uint&gt; &lt;uint&gt;
</code></pre>
<p>Jetzt sollte auch klar sein, wieso du getline() und op&gt;&gt; nicht mischen solltest, da du ja eine Zeile einliest und die uints &quot;weg&quot; sind und op&gt;&gt; aufm String dann ist...</p>
<p>Wie auch im anderen Thread geschrieben musst deine Lade Funktion so aussehen:</p>
<pre><code class="language-cpp">while(!ProjectFile.eof() &amp;&amp; !ProjectFile.fail())
{
      int size;
      ProjectFile &gt;&gt; size;

      for(int i=0;i&lt;size &amp;&amp; !ProjectFile.fail();++i)
      {
          if((ProjectFile&gt;&gt;tempBombId) &amp;&amp; (ProjectFile&gt;&gt;tempBombLaunchTime)
             &amp;&amp; (ProjectFile &gt;&gt;tempBombLaunchGroup) &amp;&amp; (ProjectFile&gt;&gt;tempBombLaunchSlot))
                                    edit(...);      
      }  
}

// Prüfen ob alles ohne Fehler gelesen wurde
</code></pre>
<p>Da benutzt du nur op&gt;&gt; und es sollten dann keine Schwirigkeiten kommen, wenn du das Speichern wie oben benutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104791</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:55:35 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 16:57:13 GMT]]></title><description><![CDATA[<p>Und immer:</p>
<p>mase schrieb:</p>
<blockquote>
<p>Doch das funktioniert nicht.</p>
</blockquote>
<p>hilft uns auch nicht weiter, du musst schon ne genau Fehlerbeschreibung liefern.</p>
<p>Aber das ist ja jetzt egal (siehe Post oben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104793</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:57:13 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 17:37:36 GMT]]></title><description><![CDATA[<p>Ich speichere immer noch ein newline zwischen den Variablen, so dass meine<br />
Datei so aussieht:</p>
<pre><code class="language-cpp">string
uint
uint
uint
</code></pre>
<p>Dann müsste ich doch nur den String mit getline() auslesen, den rest mit &gt;&gt;.<br />
Aber ich kann auch alles mit getline() auslesen, wenn ich es könnte <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/1104814</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104814</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 17:37:36 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Wed, 26 Jul 2006 21:31:42 GMT]]></title><description><![CDATA[<p>Das Speichern geht mit &gt;&gt;, ich hatte einen Fehler im Hauptprogramm, und<br />
dachte, es liegt an den Leerzeichen im String.<br />
Jetzt geht alles wunderbar!<br />
Ist die Umwandlung von uint nach string mit atoi() ok, oder sollte ich das<br />
anders machen, z. B. sprintf?<br />
Eine Typenprüfung brauch ich an dieser Stelle ja nicht, da die Zahl ja<br />
schon aus einer uint-Variable kommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104826</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104826</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Wed, 26 Jul 2006 21:31:42 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Thu, 27 Jul 2006 07:46:32 GMT]]></title><description><![CDATA[<p>Wenn du es so rausschreibst, brauchst du zum Einlesen der uints kein getline (nur für den string) und somit auch keine Konvertierung. Lies einfach direk ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105084</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 27 Jul 2006 07:46:32 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Thu, 27 Jul 2006 11:37:51 GMT]]></title><description><![CDATA[<p>Du meinst, ich soll getline für die Strings und den Ein- Ausgabeoperator für<br />
die uints mischen?<br />
Aber es funktioniert ja jetzt so.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105303</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 27 Jul 2006 11:37:51 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Thu, 27 Jul 2006 12:08:27 GMT]]></title><description><![CDATA[<p>mase schrieb:</p>
<blockquote>
<p>Du meinst, ich soll getline für die Strings und den Ein- Ausgabeoperator für<br />
die uints mischen?<br />
Aber es funktioniert ja jetzt so.</p>
</blockquote>
<p>Wenns dir gefällt unnötges kompliziert zu machen und du denkst Umwandlungen sind effizient, kannst du es so lassen <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/1105321</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105321</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 27 Jul 2006 12:08:27 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Thu, 27 Jul 2006 16:42:52 GMT]]></title><description><![CDATA[<p>Wenn getline und &gt;&gt; mischbar sind, dann hast du recht, die Konvertierung ist<br />
dann unnötig. Ich probier das mal.<br />
Ich wusste halt nur nicht, ob der Dateizeiger nach getline an der Stelle<br />
bleibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105552</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 27 Jul 2006 16:42:52 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Thu, 27 Jul 2006 17:59:55 GMT]]></title><description><![CDATA[<p>Also getline und &gt;&gt; zu mischen hat soweit funktioniert.<br />
Ich musste nur an den Stellen, wo auf ein &gt;&gt; ein getline folgt,<br />
ein getline einbauen, dass mir das newline abfängt, sonst ist das<br />
folgende getline ohne Daten, bzw. enthält nur ein newline.<br />
Dazu habe ich die bereits vorhandene Variable tempMusicFile verwendet, die<br />
in den entsprechenden Momenten nicht benötigt wird.<br />
Diese Art ist vielleicht etwas unschön, aber ich komme ohne die<br />
Konvertierungen von string nach uint aus.</p>
<pre><code class="language-cpp">//Read projectname from file
    getline(ProjectFile,ProjectName);

    //Read musiclist from file
    MusicList-&gt;clear();
    ProjectFile&gt;&gt;size;

    //Overread newline
    getline(ProjectFile,tempMusicFile);

    for(unsigned int i=0;i!=size;i++)
    {
        getline(ProjectFile,tempMusicFile);
        ProjectFile&gt;&gt;tempMusicInpoint&gt;&gt;tempMusicOutpoint&gt;&gt;tempMusicGap;
        addMusic(tempMusicFile,tempMusicInpoint,tempMusicOutpoint,static_cast&lt;Gap&gt;(tempMusicGap),i+1);

        //Overread newline
        getline(ProjectFile,tempMusicFile);
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1105594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105594</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 27 Jul 2006 17:59:55 GMT</pubDate></item><item><title><![CDATA[Reply to strings mit Leerzeichen on Mon, 31 Jul 2006 08:23:37 GMT]]></title><description><![CDATA[<p>mase schrieb:</p>
<blockquote>
<p>Also getline und &gt;&gt; zu mischen hat soweit funktioniert.<br />
Ich musste nur an den Stellen, wo auf ein &gt;&gt; ein getline folgt,<br />
ein getline einbauen, dass mir das newline abfängt, sonst ist das<br />
folgende getline ohne Daten, bzw. enthält nur ein newline.</p>
</blockquote>
<p>Klar, getline() liest bis zum nächsten \n, op&gt;&gt; lässt alles hinter der Eingabe im Speicher stehen. Alternativ könntest du auch über ignore() den Rest der Zeile komponstieren (oder über &quot;ProjectFile&gt;&gt;ws;&quot; alle Whitespaces (einschließlich \n und möglicherweise dem Anfang der folgenden Zeile) überspringen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1107523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1107523</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 31 Jul 2006 08:23:37 GMT</pubDate></item></channel></rss>