<?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[Stringdarstellung der Objekten]]></title><description><![CDATA[<p>Ich will ein Objekt als string darstellen. Später werde ich ihn in eine Datei speichern.</p>
<pre><code class="language-cpp">template &lt;class T&gt;
std::string convert_str(const T &amp;t)
{
	std::ostringstream buf(t);
	std::string x;
	buf &lt;&lt; x;
	return x;
}
</code></pre>
<p>Z.B.:</p>
<pre><code class="language-cpp">convert_str&lt;double&gt;(3.14);
</code></pre>
<p>soll als Ergebniss &quot;3.14&quot; sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149811/stringdarstellung-der-objekten</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 12:03:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149811.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Jun 2006 16:45:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stringdarstellung der Objekten on Fri, 09 Jun 2006 16:45:51 GMT]]></title><description><![CDATA[<p>Ich will ein Objekt als string darstellen. Später werde ich ihn in eine Datei speichern.</p>
<pre><code class="language-cpp">template &lt;class T&gt;
std::string convert_str(const T &amp;t)
{
	std::ostringstream buf(t);
	std::string x;
	buf &lt;&lt; x;
	return x;
}
</code></pre>
<p>Z.B.:</p>
<pre><code class="language-cpp">convert_str&lt;double&gt;(3.14);
</code></pre>
<p>soll als Ergebniss &quot;3.14&quot; sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074718</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Fri, 09 Jun 2006 16:45:51 GMT</pubDate></item><item><title><![CDATA[Reply to Stringdarstellung der Objekten on Fri, 09 Jun 2006 17:00:49 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Irgendwie sehe ich keine Frage...<br />
aber schau dir einfach <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-115176-and-highlight-is-%2Alexical%2A.html" rel="nofollow">lexicl_cast</a> an</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074725</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 09 Jun 2006 17:00:49 GMT</pubDate></item><item><title><![CDATA[Reply to Stringdarstellung der Objekten on Fri, 09 Jun 2006 17:06:21 GMT]]></title><description><![CDATA[<p>Whoops, ich habe vergessen zu sagen, dass das obige Source nicht funkzioniert. Aus einem std::string kann ich das Objekt kriegen (z.B. &lt;double&gt;&quot;3.14&quot; wird zu double 3.14). Ich dachte, dass die umgekehrte Operation mit den umgekehrten Anweisungen durchzuführen ist. Aber es klappt nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074728</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Fri, 09 Jun 2006 17:06:21 GMT</pubDate></item><item><title><![CDATA[Reply to Stringdarstellung der Objekten on Fri, 09 Jun 2006 17:11:10 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>und was hindert dich, die Funktion lexical_cast aus meinem Link zu verwenden? Denn sie macht genau das was du willst.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074729</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 09 Jun 2006 17:11:10 GMT</pubDate></item><item><title><![CDATA[Reply to Stringdarstellung der Objekten on Mon, 12 Jun 2006 11:20:44 GMT]]></title><description><![CDATA[<p>Um auf den obigen Code zurückzukommen. Der funktioniert nicht, weil stringstream keinen Konstruktor hat, welcher einen double übernimmt. Hie muß man die stream-Operatoren verwenden.</p>
<pre><code class="language-cpp">template &lt;class T&gt;
std::string convert_str(const T &amp;t)
{
    std::stringstream buf;
    buf &lt;&lt; t; 
    std::string x;
    buf &gt;&gt; x;
    return x;
}
</code></pre>
<p>oder</p>
<pre><code class="language-cpp">template &lt;class T&gt;
std::string convert_str(const T &amp;t)
{
    std::stringstream buf;
    buf &lt;&lt; t;
    return buf.str();
}
</code></pre>
<p>Man könnte hier noch eine Fehlerbehandlung einführen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1076167</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1076167</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 12 Jun 2006 11:20:44 GMT</pubDate></item><item><title><![CDATA[Reply to Stringdarstellung der Objekten on Mon, 12 Jun 2006 17:09:51 GMT]]></title><description><![CDATA[<p>Braunstein, danke sehr!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1076427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1076427</guid><dc:creator><![CDATA[khalderon]]></dc:creator><pubDate>Mon, 12 Jun 2006 17:09:51 GMT</pubDate></item></channel></rss>