C++ 문자열을 int로 변환

Jmnote (토론 | 기여)님의 2019년 1월 14일 (월) 21:54 판 (Jmnote님이 C++ String을 int로 변환 문서를 C++ string을 int로 변환 문서로 이동했습니다)

1 개요

C++ String을 int로 변환
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
	string str = "123";
	int n = atoi(str.c_str());
	cout << n << endl;
    // 123	
}
#include <iostream>
#include <sstream>
using namespace std;
int main() {
	string str = "123";
	std::stringstream ss(str);
	int n;
	ss >> n;
	cout << n << endl;
    // 123	
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}