1. 程式人生 > >C++中int 轉LPCWSTR方法,配合MessageBox使用

C++中int 轉LPCWSTR方法,配合MessageBox使用

1.MultiByteToWideChar函式方式

    int nctimes;
    string str;
	str = std::to_string(nctimes);
	size_t size = str.length();
	wchar_t *buffer = new wchar_t[size + 1];
	MultiByteToWideChar(CP_ACP, 0, str.c_str(), size, buffer, size * sizeof(wchar_t));
	buffer[size] = 0;  //確保以 '\0' 結尾 
	MessageBox(NULL, buffer, L"ddd", MB_OK);

2.to_string方式(簡單易用)

int nctimes=10;
LPCWSTR strpath=L"LL";
strpath=to_string(nctimes).c_str();

3.string轉int的方法

string str="dsdaw";

int nNub=stoi(str)