Re: Looking for an alternative to L<text>
From: MSalters (MSalters_at_discussions.microsoft.com)
Date: 01/25/05
- Next message: MSalters: "Re: uint8_t / uint16_t / uint32_t / uint64_t in streams"
- Previous message: MSalters: "RE: 'void' function returning a value (Templates)"
- In reply to: Victor Bazarov: "Re: Looking for an alternative to L<text>"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 25 Jan 2005 05:01:03 -0800
"Victor Bazarov" wrote:
...
Here is another option (using wstring):
> -------------------------------
> #include <string.h>
> #include <stdlib.h>
> #include <iostream>
> #include <string>
> #include <algorithm>
>
> std::wstring my_mbstowcs(const char* str)
> {
> int len = strlen(str);
> std::wstring w(len, 0);
> std::copy(str, str + len, w.begin());
> return w;
> }
This could be wrong if str contains cp1252 characters; wstring (in VC++)
is a UTF-16 encoding. That means the conversion you suggest is a
conversion from Latin-1. I think the main differences here are the
euro sign and chars in the range [0x80, 0xA0].
Of course, anytime a char* contains characters outside the pure
7 bits ASCII set you must be careful - which is pretty much the
reason Unicode exists in the first place.
Regards,
Michiel Salters
- Next message: MSalters: "Re: uint8_t / uint16_t / uint32_t / uint64_t in streams"
- Previous message: MSalters: "RE: 'void' function returning a value (Templates)"
- In reply to: Victor Bazarov: "Re: Looking for an alternative to L<text>"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|