<?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[Datei in einen String parsen]]></title><description><![CDATA[<p>Gibt es eine Möglichkeit eine Datei mit einem Einzeiler in einen std::string zu parsen? evtl. über Boost? Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/294312/datei-in-einen-string-parsen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 23:30:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/294312.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Oct 2011 18:41:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 18:41:03 GMT]]></title><description><![CDATA[<p>Gibt es eine Möglichkeit eine Datei mit einem Einzeiler in einen std::string zu parsen? evtl. über Boost? Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134429</guid><dc:creator><![CDATA[asdsad]]></dc:creator><pubDate>Sat, 22 Oct 2011 18:41:03 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 18:49:23 GMT]]></title><description><![CDATA[<p>asdsad schrieb:</p>
<blockquote>
<p>Gibt es eine Möglichkeit eine Datei mit einem Einzeiler in einen std::string zu parsen? evtl. über Boost? Danke</p>
</blockquote>
<p>Meinst Du, die ganze Datei mit einem Schwupps in einen String einlesen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134433</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 22 Oct 2011 18:49:23 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 18:59:20 GMT]]></title><description><![CDATA[<p>Ja, quasi. Du kannst das über Iteratoren machen:<br />
<a href="http://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring" rel="nofollow">http://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring</a></p>
<pre><code class="language-cpp">std::ifstream t(&quot;file.txt&quot;);
std::string str((std::istreambuf_iterator&lt;char&gt;(t)), std::istreambuf_iterator&lt;char&gt;());
// Die Klammern sind wichtig.
</code></pre>
<p>Aber wenn du das wirklich öfter brauchst, bietet sich eine simple Funktion eher an:</p>
<pre><code class="language-cpp">std::vector&lt;char&gt; readFile(const std::string &amp;filename)
{
    std::ifstream file;
    file.exceptions(std::ifstream::badbit | std::ifstream::eofbit | std::ifstream::failbit);
    file.open(filename, std::ios::binary);
    file.seekg(0, std::ios::end);
    std::vector&lt;char&gt; buf(static_cast&lt;std::vector&lt;char&gt;::size_type&gt;(file.tellg()));
    file.seekg(0, std::ios::beg);
    file.read(&amp;buf[0], buf.size());
    return buf;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2134434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134434</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 22 Oct 2011 18:59:20 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 18:54:46 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>asdsad schrieb:</p>
<blockquote>
<p>Gibt es eine Möglichkeit eine Datei mit einem Einzeiler in einen std::string zu parsen? evtl. über Boost? Danke</p>
</blockquote>
<p>Meinst Du, die ganze Datei mit einem Schwupps in einen String einlesen?</p>
</blockquote>
<p>Japs. Bei den Dateien handelt es sich um stylesheets die ich nicht einmal als Variable im selben Anweisungsblock brauche, ich gebe den String einfach weiter an Qt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134435</guid><dc:creator><![CDATA[asdsad]]></dc:creator><pubDate>Sat, 22 Oct 2011 18:54:46 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 19:00:27 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>...</p>
</blockquote>
<p>Danke die habe ich auch gefunden. Ich dachte einfach dass es vielleicht schon Einzeiler gibt die ich so anwenden könnte:</p>
<pre><code class="language-cpp">setStylesheet(filetostring(&quot;/styles/style.css&quot;));
</code></pre>
<p>ohne zusätzliche eigene Funktionen oder Zwischenvariablen einzuführen. In der Boost Bibliothek stecken ja öfters Schätze die darauf warten gefunden zu werden <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/2134440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134440</guid><dc:creator><![CDATA[asdsad]]></dc:creator><pubDate>Sat, 22 Oct 2011 19:00:27 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 19:07:20 GMT]]></title><description><![CDATA[<p>So etwas gibt's im Standard nicht. Aber so eine 6 Zeilen Funktion kann man sich ja auch mal selbst schreiben. <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/2134442</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134442</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 22 Oct 2011 19:07:20 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 21:32:44 GMT]]></title><description><![CDATA[<p>Vorsicht, damit das mit den Iteratoren richtig hinhaut (die benutzen operator&gt;&gt;) muss man vorher Whitespace-Skipping deaktivieren.</p>
<p>Ansonsten werfe ich mal die stringstream-Variante in die Runde:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;

std::string to_string(std::istream &amp;in) {
  std::ostringstream buffer;
  buffer &lt;&lt; in.rdbuf();
  return buffer.str();
}

std::string file_to_string(std::string const &amp;filename) {
  std::ifstream in(filename.c_str());
  return to_string(in);
}

int main() {
  std::cout &lt;&lt; file_to_string(__FILE__);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2134496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134496</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sat, 22 Oct 2011 21:32:44 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sat, 22 Oct 2011 21:53:34 GMT]]></title><description><![CDATA[<p>Wenn du Qt benutzt, könntest du auch QFile::readAll benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134502</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 22 Oct 2011 21:53:34 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sun, 23 Oct 2011 04:57:14 GMT]]></title><description><![CDATA[<p>asdsad schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>asdsad schrieb:</p>
<blockquote>
<p>Gibt es eine Möglichkeit eine Datei mit einem Einzeiler in einen std::string zu parsen? evtl. über Boost? Danke</p>
</blockquote>
<p>Meinst Du, die ganze Datei mit einem Schwupps in einen String einlesen?</p>
</blockquote>
<p>Japs. Bei den Dateien handelt es sich um stylesheets die ich nicht einmal als Variable im selben Anweisungsblock brauche, ich gebe den String einfach weiter an Qt</p>
</blockquote>
<p>Wenn du den String an QT gibst, dann nimm doch gleich QString und schlag dich nicht umständlich mit std::string rum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134555</guid><dc:creator><![CDATA[LivinInTheMovie]]></dc:creator><pubDate>Sun, 23 Oct 2011 04:57:14 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sun, 23 Oct 2011 08:40:42 GMT]]></title><description><![CDATA[<p>seldon schrieb:</p>
<blockquote>
<p>Vorsicht, damit das mit den Iteratoren richtig hinhaut (die benutzen operator&gt;&gt;) muss man vorher Whitespace-Skipping deaktivieren.</p>
</blockquote>
<p>Ähm, nicht ganz, ein istreambuf_iterator verwendet sgetc, und das filtert nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134584</guid><dc:creator><![CDATA[Cachus]]></dc:creator><pubDate>Sun, 23 Oct 2011 08:40:42 GMT</pubDate></item><item><title><![CDATA[Reply to Datei in einen String parsen on Sun, 23 Oct 2011 10:54:59 GMT]]></title><description><![CDATA[<p>Ah, richtig. Da hab ich mich stumpf verlesen (dachte an istream_iterator). Entschuldigung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2134643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2134643</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sun, 23 Oct 2011 10:54:59 GMT</pubDate></item></channel></rss>