유니코드 문자열, 숫자 변환

|

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
And
prev | 1 | 2 | 3 | 4 | ··· | 9 | next