converting string from unicode

Started by
6 comments, last by snk_kid 19 years, 8 months ago
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*
Advertisement
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.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

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).
Note that "predictable data size" helps out an awful lot with "fast random access". :/
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.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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".
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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?
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;}

This topic is closed to new replies.

Advertisement