Advertisement
KIKIJIKI

g2log wchar

Apr 3rd, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. std::string narrow(const std::wstring &s)
  2. {
  3.     size_t len = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, nullptr, 0, nullptr, nullptr);
  4.  
  5.     char* buf = new char[len];
  6.  
  7.     WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, buf, len, nullptr, nullptr);
  8.  
  9.     std::string ret(buf);
  10.  
  11.     delete[] buf;
  12.  
  13.     return ret;
  14. }
  15.  
  16. inline std::ostream& operator<<(std::ostream& out, const std::wstring& str)
  17. {
  18.         out << unicode::narrow(str);
  19.     return out;
  20. }
  21.  
  22. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
  23. {
  24.     g2LogWorker w("test", "..\\log\\");
  25.     g2::initializeLogging(&w);
  26.     LOG(INFO) << "風林火山";
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement