<?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[wchar_t zu char (Problem mit Template)]]></title><description><![CDATA[<p>Hallo, ich möchte von wchar_t zu char casten. Dazu habe ich ein Template gefunden, aber ich habe Probleme es einzubinden:</p>
<pre><code class="language-cpp">template&lt;&gt;
inline const std::basic_string&lt;char&gt; char_cast(const std::basic_string&lt;wchar_t&gt;&amp; source, const std::locale&amp; loc)
{
    char* const buf = new char[source.length()+1];

    std::use_facet&lt;std::ctype&lt;wchar_t&gt; &gt;(loc).narrow(source.data(), &amp;source.data()[source.length()], '*', buf);
    buf[source.length()] = 0;
    const std::basic_string&lt;char&gt; ret_str(buf);

    delete[] buf;

    return ret_str;
}
</code></pre>
<p>Ich bekomme folgenden Fehler beim compilieren:</p>
<pre><code>.\pda.cpp(12) : error C2039: 'locale' : is not a member of 'std'
.\pda.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\pda.cpp(12) : error C2143: syntax error : missing ',' before '&amp;'
.\pda.cpp(23) : error C2912: explicit specialization; 'const std::basic_string&lt;_Elem,_Traits,_Ax&gt; char_cast(const std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;_Ty&gt;&gt; &amp;,const int)' is not a specialization of a function template
        with
        [
            _Elem=char,
            _Traits=std::char_traits&lt;char&gt;,
            _Ax=std::allocator&lt;char&gt;,
            _Ty=wchar_t
        ]
.\pda.cpp(16) : error C2039: 'use_facet' : is not a member of 'std'
.\pda.cpp(16) : error C2065: 'use_facet' : undeclared identifier
.\pda.cpp(16) : error C2039: 'ctype' : is not a member of 'std'
.\pda.cpp(16) : error C2065: 'ctype' : undeclared identifier
.\pda.cpp(16) : error C2062: type 'wchar_t' unexpected
</code></pre>
<p>Binde ich locale über #include &lt;locale&gt;, bekomme ich</p>
<pre><code>.\pda.cpp(10) : fatal error C1083: Cannot open include file: 'locale': No such file or directory
</code></pre>
<p>Kann mir jemand helfen?</p>
<p>Gruß Jens</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/183299/wchar_t-zu-char-problem-mit-template</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 05:01:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/183299.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 03 Jun 2007 18:52:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to wchar_t zu char (Problem mit Template) on Sun, 03 Jun 2007 18:52:43 GMT]]></title><description><![CDATA[<p>Hallo, ich möchte von wchar_t zu char casten. Dazu habe ich ein Template gefunden, aber ich habe Probleme es einzubinden:</p>
<pre><code class="language-cpp">template&lt;&gt;
inline const std::basic_string&lt;char&gt; char_cast(const std::basic_string&lt;wchar_t&gt;&amp; source, const std::locale&amp; loc)
{
    char* const buf = new char[source.length()+1];

    std::use_facet&lt;std::ctype&lt;wchar_t&gt; &gt;(loc).narrow(source.data(), &amp;source.data()[source.length()], '*', buf);
    buf[source.length()] = 0;
    const std::basic_string&lt;char&gt; ret_str(buf);

    delete[] buf;

    return ret_str;
}
</code></pre>
<p>Ich bekomme folgenden Fehler beim compilieren:</p>
<pre><code>.\pda.cpp(12) : error C2039: 'locale' : is not a member of 'std'
.\pda.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\pda.cpp(12) : error C2143: syntax error : missing ',' before '&amp;'
.\pda.cpp(23) : error C2912: explicit specialization; 'const std::basic_string&lt;_Elem,_Traits,_Ax&gt; char_cast(const std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;_Ty&gt;&gt; &amp;,const int)' is not a specialization of a function template
        with
        [
            _Elem=char,
            _Traits=std::char_traits&lt;char&gt;,
            _Ax=std::allocator&lt;char&gt;,
            _Ty=wchar_t
        ]
.\pda.cpp(16) : error C2039: 'use_facet' : is not a member of 'std'
.\pda.cpp(16) : error C2065: 'use_facet' : undeclared identifier
.\pda.cpp(16) : error C2039: 'ctype' : is not a member of 'std'
.\pda.cpp(16) : error C2065: 'ctype' : undeclared identifier
.\pda.cpp(16) : error C2062: type 'wchar_t' unexpected
</code></pre>
<p>Binde ich locale über #include &lt;locale&gt;, bekomme ich</p>
<pre><code>.\pda.cpp(10) : fatal error C1083: Cannot open include file: 'locale': No such file or directory
</code></pre>
<p>Kann mir jemand helfen?</p>
<p>Gruß Jens</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1297976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1297976</guid><dc:creator><![CDATA[jensr]]></dc:creator><pubDate>Sun, 03 Jun 2007 18:52:43 GMT</pubDate></item><item><title><![CDATA[Reply to wchar_t zu char (Problem mit Template) on Sun, 03 Jun 2007 20:35:45 GMT]]></title><description><![CDATA[<p><a href="http://msdn2.microsoft.com/en-us/library/tehass7h.aspx" rel="nofollow">RTFM</a><br />
bis vor kurzem wurden auf WinCE auch keine iostreams unterstützt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1298079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1298079</guid><dc:creator><![CDATA[Superlexx]]></dc:creator><pubDate>Sun, 03 Jun 2007 20:35:45 GMT</pubDate></item><item><title><![CDATA[Reply to wchar_t zu char (Problem mit Template) on Sun, 03 Jun 2007 20:49:42 GMT]]></title><description><![CDATA[<p>Darauf bin ich noch garnicht gekommen! <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>
<p>Ich möchte lediglich Werte aus Textfeldern auslesen und als Double-Werte in einen Array speichern. (Natürlich nur, wenn es sich um zahlen handelt). Danach möchte ich eine Berechnung durchführen und die Ergebnisse in einer Datei speichern.</p>
<p>Ich muss also von</p>
<p>wchar_t -&gt; double<br />
und<br />
double -&gt; char*</p>
<p>&quot;casten&quot;.</p>
<p>Da muss es doch irgendeine Möglichkeit geben..</p>
<p>Gruß Jens</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1298092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1298092</guid><dc:creator><![CDATA[jensr]]></dc:creator><pubDate>Sun, 03 Jun 2007 20:49:42 GMT</pubDate></item><item><title><![CDATA[Reply to wchar_t zu char (Problem mit Template) on Sun, 03 Jun 2007 22:45:59 GMT]]></title><description><![CDATA[<blockquote>
<p>wchar_t -&gt; double</p>
</blockquote>
<p>swscanf</p>
<blockquote>
<p>double -&gt; char*</p>
</blockquote>
<p>sprintf</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1298141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1298141</guid><dc:creator><![CDATA[Superlexx]]></dc:creator><pubDate>Sun, 03 Jun 2007 22:45:59 GMT</pubDate></item><item><title><![CDATA[Reply to wchar_t zu char (Problem mit Template) on Mon, 04 Jun 2007 08:30:55 GMT]]></title><description><![CDATA[<p>Hallo,<br />
erstmal danke für die Hilfe.<br />
Ich möchte nun von wchar_t -&gt; double. Dafür mache ich dies:</p>
<pre><code class="language-cpp">wchar_t fieldValue[20];
double d;
swscanf(fieldValue, &quot;%f&quot;, &amp;d);
</code></pre>
<p>Ich bekomme aber:</p>
<pre><code>error C2664: 'swscanf' : cannot convert parameter 2 from 'const char [3]' to 'const wchar_t *'
</code></pre>
<p>Wo ist mein Denkfehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1298226</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1298226</guid><dc:creator><![CDATA[jensr]]></dc:creator><pubDate>Mon, 04 Jun 2007 08:30:55 GMT</pubDate></item><item><title><![CDATA[Reply to wchar_t zu char (Problem mit Template) on Mon, 04 Jun 2007 08:40:10 GMT]]></title><description><![CDATA[<p>swscanf will einen Unicode-String als Format Specifier, d.h. nicht &quot;%f&quot;, sondern <strong>L</strong>&quot;%f&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1298236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1298236</guid><dc:creator><![CDATA[Superlexx]]></dc:creator><pubDate>Mon, 04 Jun 2007 08:40:10 GMT</pubDate></item></channel></rss>