1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include "stdafx.h"
#include <string>
#include <locale>
#include <stdlib.h>
using namespace std;
wstring toWideString(const string &str)
{
size_t size = mbstowcs(NULL, str.c_str(), 0) + 1;
wchar_t *wmsg = new wchar_t[size];
mbstowcs(wmsg, str.c_str(), size);
wstring ret(wmsg);
delete wmsg;
return ret;
}
string toString(const wstring &wstr)
{
size_t size = wcstombs(NULL, wstr.c_str(), 0) + 1;
char *msg = new char[size];
wcstombs(msg, wstr.c_str(), size);
string ret(msg);
delete msg;
return ret;
}
int _tmain(int argc, _TCHAR* argv[])
{
string hello("Hello World!");
wstring hellow = toWideString(hello);
wstring byew(L"Goodbye!");
string bye = toString(byew);
return 0;
} |
Partager