Sign in to follow this  
Dovyman

converting string from unicode

Recommended Posts

Dovyman    277
How can I convert a wchar_t* to a char* ?? I've tried all sorts of methods but nothing seems to work right.. ahhhhhhhhhh *kills self*

Share this post


Link to post
Share on other sites
Etnu    880
wcstombs().

Alternatively, just stick with unicode for everything. it's only going to make things easier as more and more libraries are workign exclusively with unicode.

Share this post


Link to post
Share on other sites
bobstevens    204
UTF-16 is terrible. I doubt libraries won't start using it. Or at least I *hope* so... it seems like you can never overestimate the software industry. UTF-8 is superior in all ways but one (predictable data size).

Share this post


Link to post
Share on other sites
smart_idiot    1298
UTF-8 is my preference. It has the advantage that it's 'backward compatible' with ASCII.

But I don't know why I'm saying this since the original poster killed himself.

Share this post


Link to post
Share on other sites
Fruny    1658
Considering that UTF-16 does represent some code points as surrogate pairs, UTF-16 isn't even superior to UTF-8 in the domain of "predictable data size".

Share this post


Link to post
Share on other sites
Dovyman    277
Well in the theme of sticking totally with unicode, what I'm really trying to do is convert a string to a float.. so is there a unicode version of atof?

Share this post


Link to post
Share on other sites
snk_kid    1312
Quote:
Original post by Dovyman
How can I convert a wchar_t* to a char* ??

I've tried all sorts of methods but nothing seems to work right.. ahhhhhhhhhh *kills self*


Quote:
Original post by Dovyman
Well in the theme of sticking totally with unicode, what I'm really trying to do is convert a string to a float.. so is there a unicode version of atof?


Assuming your using c++ i not sure but what about the wide character version of stringstream? e.g.


#include <string>
#include <sstream>
#include <iostream>

int main() {

std::wstring s(L"0.545");

std::wstringstream wss(s);

float f = 0.0f;

wss >> f;

std::cout << f << '\n';

return 0;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this