<?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[Stream aus Datei auslesen]]></title><description><![CDATA[<p>Hi,</p>
<p>ich bin zur Zeit auf der Suche nach einer eleganteren oder besseren Lösung für den folgenden Code:</p>
<pre><code>long start, stop;
start = fstring.find_first_not_of(&quot;;&quot;);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.name = fstring.substr(start, stop-start).c_str();
start = fstring.find_first_not_of(&quot;;&quot;, stop);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.description = fstring.substr(start, stop-start).c_str();
start = fstring.find_first_not_of(&quot;;&quot;, stop);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.size = atol(fstring.substr(start, stop-start).c_str());
start = fstring.find_first_not_of(&quot;;&quot;, stop);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.sell = atol(fstring.substr(start, stop-start).c_str());
</code></pre>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/263093/stream-aus-datei-auslesen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 04:59:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/263093.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Mar 2010 20:58:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stream aus Datei auslesen on Mon, 15 Mar 2010 20:58:17 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich bin zur Zeit auf der Suche nach einer eleganteren oder besseren Lösung für den folgenden Code:</p>
<pre><code>long start, stop;
start = fstring.find_first_not_of(&quot;;&quot;);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.name = fstring.substr(start, stop-start).c_str();
start = fstring.find_first_not_of(&quot;;&quot;, stop);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.description = fstring.substr(start, stop-start).c_str();
start = fstring.find_first_not_of(&quot;;&quot;, stop);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.size = atol(fstring.substr(start, stop-start).c_str());
start = fstring.find_first_not_of(&quot;;&quot;, stop);
stop = fstring.find_first_of(&quot;;&quot;, start);
myclass.sell = atol(fstring.substr(start, stop-start).c_str());
</code></pre>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1869536</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869536</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Mon, 15 Mar 2010 20:58:17 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Mon, 15 Mar 2010 21:14:26 GMT]]></title><description><![CDATA[<p>Neeeeein, gar nicht dreist... ^^<br />
Um was geht's denn? Geht's allgemeiner?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1869551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869551</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Mon, 15 Mar 2010 21:14:26 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Tue, 16 Mar 2010 16:52:27 GMT]]></title><description><![CDATA[<p>Mal davon ausgegangen das du fstring erst mal über ifstream eingelesen hast</p>
<pre><code class="language-cpp">template&lt; typename ConvertTo &gt;
void convert( ConvertTo &amp; to, std::string const &amp; from ){
   // Falls boost vorhanden besser auf boost::lexical_cast&lt; ConvertTo &gt; zurückgreifen
   std::istringstream istr( from );
   istr &gt;&gt; to;
   // throw exception on error
}

void convert( std::string &amp; to, std::string const &amp; from ){
   to = from;
}

struct Data {
  std::string data;
  std::string description;
  long size;
  long sell;

  template&lt; typename TargetT &gt;
  void read( std::istream &amp; is, TargetT &amp; target ){
      std::string value;
      if( std::getline( is, value, ';' ) ){
         convert( target, value );
      }
      else {
        // throw exception 
      } 
  }
  void fromString( std::string const &amp; line ){
      std::istringstream istr( line );
      read( ostr, name );
      read( ostr, description );
      read( ostr, size );
      read( ostr, sell );
  }
};

// std::ifstream ifs... falls von einem string dann kannst du std::istringstream verwenden 
std::string line;
while( std::getline( ifs, line) ) {
   Data myclass;
   myclass.fromString( line );
}
</code></pre>
<p>Deins ist natürlich kürzer aber man könnte das so in der art lösen</p>
<p>BR</p>
<p>Edit: ostream &lt;=&gt; istream <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1869552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869552</guid><dc:creator><![CDATA[evilissimo]]></dc:creator><pubDate>Tue, 16 Mar 2010 16:52:27 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Mon, 15 Mar 2010 21:41:31 GMT]]></title><description><![CDATA[<p>Hallo Scarabol,</p>
<p>wie sieht die Datei aus, die in <code>fstring</code> eingelesen wurde. Und welche Texte oder Zahlen möchtest Du in welche Variablen einlesen. Das geht auf jeden Fall besser als dieses String-auseinander-gefiesele.<br />
Aber hilfreicher als der Code den Du geschrieben hast, wäre das Format der Datei.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1869568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869568</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 15 Mar 2010 21:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Tue, 16 Mar 2010 15:30:18 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>die Datei hat folgendes Format:</p>
<pre><code>// Kommentar
0;250;5;10;0;data/texture.png;
0;125;7;13;1;data/texture2.png;
...
</code></pre>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1869906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869906</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Tue, 16 Mar 2010 15:30:18 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Tue, 16 Mar 2010 16:19:33 GMT]]></title><description><![CDATA[<p>Hallo Scarabol,</p>
<p>dann verwende doch die normalen Stream-Operatoren:</p>
<pre><code class="language-cpp">std::istringstream istr(fstring);

char c;
istr &gt;&gt; myclass.x &gt;&gt; c &gt;&gt; myclass.y &gt;&gt; c &gt;&gt; myclass.z; // für Zahlenwerte
// bzw.
std::getline(istr, myclass.name, ';'); // für Strings
</code></pre>
<p>Zur Sicherheit könntest du dann auch noch die Variable c überprüfen, ob dort wirklich ein Semikolon drin steht.</p>
<p>P.S. evilissimo, deine read-Funktion sollte wohl eher einen istream entgegennehmen: void read( std::istream &amp; is, ...)<br />
ebenso fromString: std::istringstream istr( line ) <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/1869932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869932</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Tue, 16 Mar 2010 16:19:33 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Tue, 16 Mar 2010 16:50:47 GMT]]></title><description><![CDATA[<p>lol ja sollte es eigentlich. Ich hab das nicht getestet. Nur so runter geschrieben :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1869955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1869955</guid><dc:creator><![CDATA[evilissimo]]></dc:creator><pubDate>Tue, 16 Mar 2010 16:50:47 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Wed, 17 Mar 2010 17:47:29 GMT]]></title><description><![CDATA[<p>Danke, genau das hab ich gesucht.</p>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1870509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1870509</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Wed, 17 Mar 2010 17:47:29 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Sun, 21 Mar 2010 13:47:48 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>also irgendwie kann ich getline nicht mit std::string benutzen, er will immer ein char * haben, wieso?</p>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1872024</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1872024</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Sun, 21 Mar 2010 13:47:48 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Sun, 21 Mar 2010 13:52:21 GMT]]></title><description><![CDATA[<p>Scarabol schrieb:</p>
<blockquote>
<p>Hi,</p>
<p>also irgendwie kann ich getline nicht mit std::string benutzen, er will immer ein char * haben, wieso?</p>
<p>MfG<br />
Scarabol</p>
</blockquote>
<p>Weil es zwei getlines gibt, und du anscheinend das flasche benutzt. Das eine ist eine Memberfunktion von istream und will einen char*:<br />
<a href="http://www.cplusplus.com/reference/iostream/istream/getline/" rel="nofollow">http://www.cplusplus.com/reference/iostream/istream/getline/</a></p>
<p>Das andere ist eine freie Funktion im string Header und will einen std::string:<br />
<a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">http://www.cplusplus.com/reference/string/getline/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1872027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1872027</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 21 Mar 2010 13:52:21 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Sun, 21 Mar 2010 13:57:39 GMT]]></title><description><![CDATA[<p>oh mann, ich depp vielen dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1872031</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1872031</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Sun, 21 Mar 2010 13:57:39 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Sun, 21 Mar 2010 14:26:09 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>noch eine Frage:</p>
<p>Ich habe ein stringstream objekt mit folgendem Inhalt:<br />
&quot;10,20;20,30;<em>;&quot;<br />
wie kann ich nun aus diesem stream sub streams erzeugen so das ich folgendes erhalte:<br />
sub1 &quot;10,20&quot;<br />
sub2 &quot;20,30&quot;<br />
sub3 &quot;</em>&quot;</p>
<p>sub1,2,3 sollten vom Typ stringstream sein.</p>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1872050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1872050</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Sun, 21 Mar 2010 14:26:09 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Sun, 21 Mar 2010 17:51:29 GMT]]></title><description><![CDATA[<p>Scarabol schrieb:</p>
<blockquote>
<p>Ich habe ein stringstream objekt mit folgendem Inhalt:<br />
&quot;10,20;20,30;<em>;&quot;<br />
wie kann ich nun aus diesem stream sub streams erzeugen so das ich folgendes erhalte:<br />
sub1 &quot;10,20&quot;<br />
sub2 &quot;20,30&quot;<br />
sub3 &quot;</em>&quot;</p>
<p>sub1,2,3 sollten vom Typ stringstream sein.</p>
</blockquote>
<p>Zum Beispiel so:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;sstream&gt;

int main()
{
    using namespace std;
    istringstream inhalt(&quot;10,20;20,30;*;&quot;);
    for( string s; getline( inhalt, s, ';' ); )
    {
        stringstream sub( s );
        cout &lt;&lt; &quot;Der Inhalt des stringstream ist: &quot; &lt;&lt; sub.str() &lt;&lt; endl;
    }
    return 0;
}
</code></pre>
<p>.. wofür soll das gut sein? Ich glaub' das geht noch besser, wenn Du uns erzählst zu was Du den Inhalt in stringstreams benötigst. I.A. kann man sich die stringstreams sparen.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1872156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1872156</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sun, 21 Mar 2010 17:51:29 GMT</pubDate></item><item><title><![CDATA[Reply to Stream aus Datei auslesen on Fri, 02 Apr 2010 08:08:34 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>der Inhalt des Stringstreams enthält die Daten die ich für das Programm brauche und die statisch sind. Wie z.B. Daten für Raumschiffe, Frachtgüter oder Stationen ect.</p>
<p>MfG<br />
Scarabol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1876715</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1876715</guid><dc:creator><![CDATA[Scarabol]]></dc:creator><pubDate>Fri, 02 Apr 2010 08:08:34 GMT</pubDate></item></channel></rss>