문자열을 숫자로 바꿀 때 sscanf() 함수를 사용한다.

http://codepad.org/z5sH9O1u
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cstdio>
 
int main ()
{
        int num;
        unsigned int unum;
 
        sscanf("0xFF", "%x", &unum);
        std::cout << unum << std::endl;
        sscanf("255", "%d", &num);
        std::cout << num << std::endl;
 
        sscanf("377", "%o", &unum);
        std::cout << unum << std::endl;
 
        return 0;
}


Output:
1
2
3
255
255
255

+ Recent posts