get length of `wchar_t*` in c++
If you want to know the size of a wchar_t string (wchar_t *), you want to use wcslen(3): size_t wcslen (const wchar_t *ws);
If you want to know the size of a wchar_t string (wchar_t *), you want to use wcslen(3): size_t wcslen (const wchar_t *ws);
Use wstring, see this code: // Your wchar_t* wchar_t* txt = L”Hello World”; wstring ws(txt); // your new String string str(ws.begin(), ws.end()); // Show String cout << str << endl;
std::wstring ws( args.OptionArg() ); std::string test( ws.begin(), ws.end() );
Is this the right way to write an idiomatic, portable, universal, encoding-agnostic program core using only pure standard C/C++ No, and there is no way at all to fulfill all these properties, at least if you want your program to run on Windows. On Windows, you have to ignore the C and C++ standards almost … Read more
First convert it to std::wstring: std::wstring widestr = std::wstring(str.begin(), str.end()); Then get the C string: const wchar_t* widecstr = widestr.c_str(); This only works for ASCII strings, but it will not work if the underlying string is UTF-8 encoded. Using a conversion routine like MultiByteToWideChar() ensures that this scenario is handled properly.
To represent the character you can use Universal Character Names (UCNs). The character ‘ф’ has the Unicode value U+0444 and so in C++ you could write it ‘\u0444’ or ‘\U00000444’. Also if the source code encoding supports this character then you can just write it literally in your source code. // both of these assume … Read more
The short answer: NO. Like all the others already wrote, a lot of programmers still use TCHARs and the corresponding functions. In my humble opinion the whole concept was a bad idea. UTF-16 string processing is a lot different than simple ASCII/MBCS string processing. If you use the same algorithms/functions with both of them (this … Read more
Edit: This doesn’t work if you are trying to write text that cannot be represented in your default locale. 🙁 Use std::wcout instead of std::cout. wcout << ru << endl << en;