Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- std::cout << u8"это строка6" << std::endl;
- return 0;
- }
- ��то строка6
- #include <iostream>
- #include <windows.h>
- #include <fcntl.h>
- #include <io.h>
- #include <iostream> // std::wcerr
- std::wstring strtows(const std::string &str, UINT codePage)
- {
- std::wstring ws;
- int n = MultiByteToWideChar(codePage, 0, str.c_str(), static_cast<int>(str.size()), NULL, 0);
- if (n) {
- ws.resize(n);
- if (MultiByteToWideChar(codePage, 0, str.c_str(), static_cast<int>(str.size()), &ws[0], n) == 0)
- ws.clear();
- }
- return ws;
- }
- std::string wstostr(const std::wstring &ws, UINT codePage)
- {
- // prior to C++11 std::string and std::wstring were not guaranteed to have their memory be contiguous,
- // although all real-world implementations make them contiguous
- std::string str;
- int srcLen = static_cast<int>(ws.size());
- int n = WideCharToMultiByte(codePage, 0, ws.c_str(), srcLen, NULL, 0, 0, NULL);
- if (n) {
- str.resize(n);
- if (WideCharToMultiByte(codePage, 0, ws.c_str(), srcLen, &str[0], n, 0, NULL) == 0)
- str.clear();
- }
- return str;
- }
- std::string WstringToUtf8(const std::wstring &str)
- {
- return wstostr(str, CP_UTF8);
- }
- std::wstring Utf8ToWstring(const std::string &str)
- {
- return strtows(str, CP_UTF8);
- }
- int main(int argc, char *argv[])
- {
- _setmode(_fileno(stdout), _O_U16TEXT);
- std::wcout << Utf8ToWstring(u8"это строка6") << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement