Cross platform C++
Does it matter whether I use char or wchar_t? Which one should I use (when I deal with individual characters, don''t worry, I am using std::string)?
Cross platform doesn''t have anything to do with wide characters, but international does. If you plan on having people from other countries using your app or game, then you should use wide chars.
It''s generally a good idea to stick with unicode ("wchar_t") data types in general, as many programming languages always use it, and all the standard functions work with it anyway. character arrays are kind of ugly anyway.
I know STL gives you a choice (with strings). I was wondering which one to use, and I think I will use wide chars because ASCII is being phased out.
EDIT: Never mind.
OK, I am having trouble using wchar_t. The compiler can't convert things inside of quotes to wstrings.
I get this error: cannot convert from 'const char [61]' to 'const std::wstring'
Is there a pre-quote character I should put to fix this (like #"text")?
EDIT: Yes, L.
[edited by - thedevdan on June 6, 2004 4:56:47 PM]
OK, I am having trouble using wchar_t. The compiler can't convert things inside of quotes to wstrings.
I get this error: cannot convert from 'const char [61]' to 'const std::wstring'
Is there a pre-quote character I should put to fix this (like #"text")?
EDIT: Yes, L.
[edited by - thedevdan on June 6, 2004 4:56:47 PM]
quote:Original post by dcosborn
I believe its an L:
L"This is a wide-character string."
Yeah, I just found it while searching the forums. Thanks a lot, though.
Goes to show you should search before asking...
you can also use the _T() macro (defined in the tchar header):
#ifdef _UNICODE
#define _T(x) L ## x
#else
#define _T(x) x
_T("Here is a string.")
#ifdef _UNICODE
#define _T(x) L ## x
#else
#define _T(x) x
_T("Here is a string.")
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement