Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable wchar_t in C++

Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it.

like image 713
Daniel A. White Avatar asked Jan 21 '09 21:01

Daniel A. White


1 Answers

If you're dealing with use internal to the program, don't worry about it; a wchar_t in class A is the same as in class B.

If you're planning to transfer data between Windows and Linux/MacOSX versions, you've got more than wchar_t to worry about, and you need to come up with means to handle all the details.

You could define a type that you'll define to be four bytes everywhere, and implement your own strings, etc. (since most text handling in C++ is templated), but I don't know how well that would work for your needs.

Something like typedef int my_char; typedef std::basic_string<my_char> my_string;

like image 70
David Thornley Avatar answered Oct 08 '22 19:10

David Thornley