<?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[char stringstream, geht das schöner?]]></title><description><![CDATA[<p>Hallo!</p>
<p>Mein Fileformat sieht am Beginn eines Files einen genau 1024 Byte großen<br />
Informationsblock vor. Das habe ich momentan so gelöst:</p>
<p>// The info header<br />
const unsigned LEN(1024);<br />
char info[LEN];<br />
stringstream sstr;<br />
sstr &lt;&lt; &quot;Beispielstring: &lt;&quot; &lt;&lt; einString &lt;&lt; &quot;&gt; und &lt;&quot; &lt;&lt; eineZahl &lt;&lt; &quot;&gt;&quot;&lt;&lt;endl;<br />
strncpy(info,sstr.str().c_str(),LEN);<br />
info[LEN-1]='\0';</p>
<p>// Write the info header<br />
outFile.write(info,LEN);</p>
<p>Gerade bei Zeichenketten gibts aber bekanntlich viele Möglichkeiten, das Ziel<br />
zu erreichen. Wie würde man denn diese Aufgabe kürzer und herzeigbarer lösen?</p>
<p>lg<br />
bts</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252913/char-stringstream-geht-das-schöner</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 04:13:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252913.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Oct 2009 11:49:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to char stringstream, geht das schöner? on Mon, 26 Oct 2009 11:49:41 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Mein Fileformat sieht am Beginn eines Files einen genau 1024 Byte großen<br />
Informationsblock vor. Das habe ich momentan so gelöst:</p>
<p>// The info header<br />
const unsigned LEN(1024);<br />
char info[LEN];<br />
stringstream sstr;<br />
sstr &lt;&lt; &quot;Beispielstring: &lt;&quot; &lt;&lt; einString &lt;&lt; &quot;&gt; und &lt;&quot; &lt;&lt; eineZahl &lt;&lt; &quot;&gt;&quot;&lt;&lt;endl;<br />
strncpy(info,sstr.str().c_str(),LEN);<br />
info[LEN-1]='\0';</p>
<p>// Write the info header<br />
outFile.write(info,LEN);</p>
<p>Gerade bei Zeichenketten gibts aber bekanntlich viele Möglichkeiten, das Ziel<br />
zu erreichen. Wie würde man denn diese Aufgabe kürzer und herzeigbarer lösen?</p>
<p>lg<br />
bts</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798483</guid><dc:creator><![CDATA[.bts]]></dc:creator><pubDate>Mon, 26 Oct 2009 11:49:41 GMT</pubDate></item><item><title><![CDATA[Reply to char stringstream, geht das schöner? on Mon, 26 Oct 2009 11:54:03 GMT]]></title><description><![CDATA[<p>falls dein Outfile vom Typ fstream ist, kannst du auch direkt über die operatoren in die Datei schreiben, das heiß genau wie du das mit dem stringstream machst!<br />
kannst dir dann den rest schon mal sparen und alles sieht schon mal besser aus <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/1798485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798485</guid><dc:creator><![CDATA[newbie1243]]></dc:creator><pubDate>Mon, 26 Oct 2009 11:54:03 GMT</pubDate></item><item><title><![CDATA[Reply to char stringstream, geht das schöner? on Mon, 26 Oct 2009 12:06:36 GMT]]></title><description><![CDATA[<p>newbie1243 schrieb:</p>
<blockquote>
<p>falls dein Outfile vom Typ fstream ist, kannst du auch direkt über die operatoren in die Datei schreiben, das heiß genau wie du das mit dem stringstream machst!<br />
kannst dir dann den rest schon mal sparen und alles sieht schon mal besser aus <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>
</blockquote>
<p>Ja, aber was ich da reinschreibe, hat eine variable Größe. Wie würde ich also<br />
auf die Art sicherstellen, daß der Infoblock exakt 1024 Bytes lang ist?</p>
<p>lg<br />
bts</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798492</guid><dc:creator><![CDATA[.bts]]></dc:creator><pubDate>Mon, 26 Oct 2009 12:06:36 GMT</pubDate></item><item><title><![CDATA[Reply to char stringstream, geht das schöner? on Mon, 26 Oct 2009 12:50:15 GMT]]></title><description><![CDATA[<p>Übrigens steht zwischen dem String und dem LEN-1 einfach Müll. Initialisiere info.</p>
<p>Edit: Stimmt natürlich nicht, wird mit 0 gepaddet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798508</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 26 Oct 2009 12:50:15 GMT</pubDate></item><item><title><![CDATA[Reply to char stringstream, geht das schöner? on Mon, 26 Oct 2009 13:27:32 GMT]]></title><description><![CDATA[<p>Was steht denn in dem Infoblock drin? Vielleicht kann man den besser über eine Struktur abbilden, für die man die stream operatoren &lt;&lt; und &gt;&gt; überlädt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798535</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 26 Oct 2009 13:27:32 GMT</pubDate></item><item><title><![CDATA[Reply to char stringstream, geht das schöner? on Mon, 26 Oct 2009 15:43:45 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Was steht denn in dem Infoblock drin? Vielleicht kann man den besser über eine Struktur abbilden, für die man die stream operatoren &lt;&lt; und &gt;&gt; überlädt.</p>
</blockquote>
<p>In einer Toolchain werden mehrfach Files gelesen/geschrieben. Das Info-Element<br />
beinhaltet da verschiedene Daten. Meinst Du sowas?</p>
<p>struct InfoBlock<br />
{<br />
char text[1024];<br />
operator&lt;&lt;(string s)<br />
{<br />
somehow append s to text;<br />
}<br />
};</p>
<p>Das wäre natürlich eine Möglichkeit. Ist auch beim Einlesen sauberer.</p>
<p>lg<br />
bts</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798635</guid><dc:creator><![CDATA[.bts]]></dc:creator><pubDate>Mon, 26 Oct 2009 15:43:45 GMT</pubDate></item></channel></rss>