int를 스트링으로 바꾸고 싶어요
조회수 37120회
제가 알고 있는 방법 말고 int형을 string으로 바꾸는 제일 쉬운 방법좀 알려주세요!
소스 코드
//1.
int a = 10;
char *intStr = itoa(a);
string str = string(intStr);
//2.
int a = 10;
stringstream ss;
ss << a;
string str = ss.str();
1 답변
-
C++0x의 std::stoi, std::to_string은 어떤가요?
std::string s = std::to_string(42); std::string s = std::to_stoi(42);
와 같이 사용하면 됩니다.
댓글 입력