C++ 문자열을 int로 변환

Jmnote (토론 | 기여)님의 2019년 1월 14일 (월) 21:53 판 (새 문서: ==개요== ;C++ String을 int로 변환 <source lang='cpp'> #include <iostream> #include <stdlib.h> using namespace std; int main() { string str = "123"; int n = atoi(str.c_str());...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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 }}