<?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[boost lexical cast macht mit wstring probleme]]></title><description><![CDATA[<p>Ne lib verwendet anstatt std::string std::wstring.</p>
<p>Ich muss an einer stelle einen wstring in einen string casten, dafür wollte ich nen lexical cast nutzen. Meine Lib ist 1.36.0 (ich update grade auf 1.37.0)</p>
<p>Der simple code<br />
<a href="http://codepad.org/MBqPhhaL" rel="nofollow">http://codepad.org/MBqPhhaL</a><br />
Anstatt wfoo hat wfoo.c_str() auch nicht geklappt</p>
<p>Es kommt eine Fehlermeldung, wenn auch eine andere, als die bei codepad (welche ich nicht posten kann, weil ich boost update und kein lexical cast mehr habe)</p>
<p>Ist dies generell ein problem ? In die andere Richtung ist es eigentlich kein Thema, aber von wstring nach string klappts nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/229413/boost-lexical-cast-macht-mit-wstring-probleme</link><generator>RSS for Node</generator><lastBuildDate>Mon, 28 Sep 2026 00:06:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/229413.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Dec 2008 13:38:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost lexical cast macht mit wstring probleme on Thu, 11 Dec 2008 13:40:01 GMT]]></title><description><![CDATA[<p>Ne lib verwendet anstatt std::string std::wstring.</p>
<p>Ich muss an einer stelle einen wstring in einen string casten, dafür wollte ich nen lexical cast nutzen. Meine Lib ist 1.36.0 (ich update grade auf 1.37.0)</p>
<p>Der simple code<br />
<a href="http://codepad.org/MBqPhhaL" rel="nofollow">http://codepad.org/MBqPhhaL</a><br />
Anstatt wfoo hat wfoo.c_str() auch nicht geklappt</p>
<p>Es kommt eine Fehlermeldung, wenn auch eine andere, als die bei codepad (welche ich nicht posten kann, weil ich boost update und kein lexical cast mehr habe)</p>
<p>Ist dies generell ein problem ? In die andere Richtung ist es eigentlich kein Thema, aber von wstring nach string klappts nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1628860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1628860</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 11 Dec 2008 13:40:01 GMT</pubDate></item><item><title><![CDATA[Reply to boost lexical cast macht mit wstring probleme on Thu, 11 Dec 2008 13:42:06 GMT]]></title><description><![CDATA[<p>Dafür ist Lexical Cast nicht gedacht, daher wird das nie funktionieren. Da müsstest du ziemlich hässliche Workarounds bauen, also unsinnig.</p>
<p><code>std::string &lt;-&gt; std::wstring</code> macht man so:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-168607.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-168607.html</a></p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1628863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1628863</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 11 Dec 2008 13:42:06 GMT</pubDate></item><item><title><![CDATA[Reply to boost lexical cast macht mit wstring probleme on Thu, 11 Dec 2008 14:35:20 GMT]]></title><description><![CDATA[<p>Hm,<br />
das hier</p>
<pre><code class="language-cpp">helper::Widen&lt;char&gt; toString;
	std::wstring wfoo = L&quot;Foooo&quot;;
	std::string foo = toString(wfoo);
</code></pre>
<p>Ist nicht so erfolgreich</p>
<blockquote>
<p>Error 1 error C2664: 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; helper::Widen&lt;E&gt;::operator ()(const std::string &amp;) const' : cannot convert parameter 1 from 'const wchar_t *' to 'const std::string &amp;' d:\writer.cpp 1266</p>
</blockquote>
<p>Mir geht es ja um wstring2string</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1628892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1628892</guid><dc:creator><![CDATA[Seikilos]]></dc:creator><pubDate>Thu, 11 Dec 2008 14:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to boost lexical cast macht mit wstring probleme on Thu, 11 Dec 2008 15:07:46 GMT]]></title><description><![CDATA[<p>Seikilos schrieb:</p>
<blockquote>
<p>Mir geht es ja um wstring2string</p>
</blockquote>
<p>Sorry, dachte im Thread würde dazu auch was stehen.</p>
<p>Grundsätzlich geht es in die andere Richtung, mit der Funktion <code>narrow</code> , satt <code>widen</code> . Allerdings muss ich gestehen, dass es bei mir gerade nicht so korrekt funktioniert hat und habe das schon länger nicht mehr gemacht.</p>
<p>Es geht aber irgendwie so:</p>
<pre><code class="language-cpp">#include &lt;locale&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

// ...

std::string narrow(std::wstring const&amp; wstr,
				   char defaultChar = ' ',
				   std::locale const&amp; locale = std::locale())
{
	std::wstring::size_type srcSize = wstr.size();
	wchar_t const* src = wstr.c_str();

	std::vector&lt;char&gt; buffer(srcSize);

	std::ctype&lt;wchar_t&gt; const&amp; ctype
		= std::use_facet&lt;std::ctype&lt;wchar_t&gt; &gt;(locale);

	ctype.narrow(src, src + srcSize,
				 defaultChar,
				 &amp;buffer[0]);

	return std::string(buffer.begin(), buffer.end());
}
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1628924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1628924</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 11 Dec 2008 15:07:46 GMT</pubDate></item></channel></rss>