wchar_t zu char (Problem mit Template)
-
Hallo, ich möchte von wchar_t zu char casten. Dazu habe ich ein Template gefunden, aber ich habe Probleme es einzubinden:
template<> inline const std::basic_string<char> char_cast(const std::basic_string<wchar_t>& source, const std::locale& loc) { char* const buf = new char[source.length()+1]; std::use_facet<std::ctype<wchar_t> >(loc).narrow(source.data(), &source.data()[source.length()], '*', buf); buf[source.length()] = 0; const std::basic_string<char> ret_str(buf); delete[] buf; return ret_str; }Ich bekomme folgenden Fehler beim compilieren:
.\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 '&' .\pda.cpp(23) : error C2912: explicit specialization; 'const std::basic_string<_Elem,_Traits,_Ax> char_cast(const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<_Ty>> &,const int)' is not a specialization of a function template with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char>, _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' unexpectedBinde ich locale über #include <locale>, bekomme ich
.\pda.cpp(10) : fatal error C1083: Cannot open include file: 'locale': No such file or directoryKann mir jemand helfen?
Gruß Jens
-
RTFM
bis vor kurzem wurden auf WinCE auch keine iostreams unterstützt
-
Darauf bin ich noch garnicht gekommen!

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.
Ich muss also von
wchar_t -> double
und
double -> char*"casten".
Da muss es doch irgendeine Möglichkeit geben..
Gruß Jens
-
wchar_t -> double
swscanf
double -> char*
sprintf
-
Hallo,
erstmal danke für die Hilfe.
Ich möchte nun von wchar_t -> double. Dafür mache ich dies:wchar_t fieldValue[20]; double d; swscanf(fieldValue, "%f", &d);Ich bekomme aber:
error C2664: 'swscanf' : cannot convert parameter 2 from 'const char [3]' to 'const wchar_t *'Wo ist mein Denkfehler?
-
swscanf will einen Unicode-String als Format Specifier, d.h. nicht "%f", sondern L"%f"