Converting string types

I've been trying to figure out how to convert a c string that uses a char pointer to a wide c string that uses a wchar_t pointer. I can't figure out what function that I can use to do this. I looked on MSDN and the only remotely helpful thing I found was MultibyteToWideChar but from what I saw it can be dangerous to use if you don't know what your doing, aka me trying to use it.Anybody have a better suggestion?
wcstombs_s - Wide Character String to Multi Byte String (Secure version)
mbstowcs_s - Multi Byte String to Wide Character String (Secure version)
Last edited on
char src[1024];
wchar_t dst[1024];
std::copy(src,src+1024,dst); //(will trigger a warning)
The mbstowcs_s worked great thanks for the help guys!
Grrr...
helios, don't we try to discourage warnings?
Don't trust all VC++ warnings, some of them tell you to use nonstandard functions.
Each function with a '_' in its name isn't standard
Warnings are warnings. You can ignore them if you understand them.
In the example, the warning is about assigning things of different sizes. You can ignore it because that's the whole point of the call. Moving from one size to another.

And a warning is a lot better than using non-standard functions.
Last edited on
Well is there some way to tell the compiler to ignore it? Or do I just have look through and say this warning doesn't mean anything?
Depends on your compiler. #pragma warning(disable:4244) should do the trick for VC++.
I got it to ignore the warning but the disable code was 4996 in this case. Thanks a bunch though.
Wait. What? C4996 is the unsafe functions warning. What are you doing over there?
When I tried to compile with the exact preprocessor you gave me the warning persisted. I looked at the warning and it gave me 4996 as the warning code for the copy function. I disabled 4996 and the warning went away. I'm using VS C++ 2008 if it makes a difference.
Each function with a '_' in its name isn't standard

Not yet at least.
What are you implying?
the _s functions have been proposed in the c library technical report

http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1225.pdf
Oh, that's just for C. It'll be some time until they get added to C++, if they ever are. They're definitely not going to be included in C++0x, so it'll probably be at least another ten years.
Just tossing in my own 2MiB, but there IS at least one function in the C++ standard that has a _.
std::string::c_str();
OK, Most of the functions with a '_' in their name aren't standard.
Is everybody happy now?
BTW, c_str can be said as a 'method' I meant global functions
Topic archived. No new replies allowed.