stdio.h, string, windows.h 추가
std::wstring itou(int number) // Int To Unicode
{
char multibyte_string[32];
itoa(number,multibyte_string,10);
wchar_t szResultString[32];
MultiByteToWideChar(CP_ACP,0,(LPSTR)multibyte_string,-1,szResultString,32);
std::wstring returnString = szResultString;
return returnString;
}
int utoi(wchar_t * s) //Unicode To Int
{
int i, n;
n = 0;
for (i = 0; s[i] >= L'0' && s[i] <= L'9'; ++i)
n = 10 * n + (s[i] - L'0');
return n;
}
사용법
#include <string>
#include <stdio.h>
#include <windows.h>
/*
* 위의 함수들 정의
* 위의 함수들 정의
*/
int main(void)
{
int a = utoi(L"1234");
printf("%d\n",a); // result : 1234
wprintf(L"%s\n", itou(a).c_str()); //result : 1234
}
출처> http://breadlab.wo.tc/220
'메모 > C/C++' 카테고리의 다른 글
| Direct2D 동적변수(?) 텍스트로 그리기 (0) | 2012.04.19 |
|---|---|
| char* -> WCHAR* (wchar_t*) MultiByteToWideChar 함수 (0) | 2012.04.16 |
| converting float to string, string to float (0) | 2012.04.14 |
| char -> int 변환 (0) | 2012.04.10 |
| Direct2D and Direct3D Interoperability Overview (0) | 2012.04.04 |
