c++ - Assigning a "const char*" to std::string is allowed, but assigning to std::wstring doesn't compile. Why? -
I assume that std :: wstring and std :: string both provide the same interface.
So I tried to enable Unicode capabilities for our application
# ifdef APP_USE_UIIOCOED Typedef std :: wstring AppStringType; # Else typedef std :: string AppStringType; #AndIF
But when I-DAPP_USSEUIOOODIEE is used, I get many compile errors.
It turned on, that when a const char []
to std :: wstring
.
Edit is assigned: Better example by removing the use of literal "Hello".
#include & lt; String & gt; Zero myfunc (const char h []) {string s = h; // compiles ok wstring w = h; // compile error}
Why does this make a difference?
A const char * from
to
is allowed std :: string
, but specifying std :: wstring
gives.
std :: wstring
should not do this as the std :: string
interface?
(Environment: GBC-4.4.1 on Ubuntu Karmic 32 bit)
The relevant part of the string API is this manufacturer:
basic_string (const charT *);
for std :: string, char char is std :: wstring for it wchar_t so it does not compile that wstring does not have a four * constructor why not wstring a Four * manufacturer?
There is no unique way to convert a string of four letters to wchar. What is encoding with four strings? Is it just 7 bit ASCII? Is this UTF-8? Is this UTF-7? Is this SHIFT-JIS? So I do not think it can fully understand std :: wstring for doing an auto conversion from around, although you can cover most cases you can use it:
< Pre> w = std :: wstring (h, h + sizeof (h) - 1);
Each letter will turn in turn (except for the NUL terminator), and what you want in this example is what you call intase 3, if that is the case, it means that It would be better to use a broad string in the first place.
Comments
Post a Comment