Last active
August 29, 2015 14:25
-
-
Save Tosainu/f36581dc8cf624ddfbc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if !defined HELPER_HPP | |
#define HELPER_HPP | |
#include <codecvt> | |
#include <locale> | |
#include <string> | |
namespace helper { | |
std::string to_string(const std::wstring& src) { | |
static std::wstring_convert<std::codecvt_utf8<wchar_t>> conv; | |
return conv.to_bytes(src); | |
} | |
std::wstring to_wide(const std::string& src) { | |
static std::wstring_convert<std::codecvt_utf8<wchar_t>> conv; | |
return conv.from_bytes(src); | |
} | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "helper.hpp" | |
auto main() -> int { | |
const std::string str("std::string!!"); | |
const std::wstring wstr(L"std::wstring!!"); | |
const std::string from_wstring = helper::to_string(wstr); | |
const std::wstring from_string = helper::to_wide(str); | |
std::cout << from_wstring << '\n'; | |
std::wcout << from_string << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment