1. string to int 변환 / stoi() 함수

#include <iostream>
#include <string> // stoi() 함수 사용을 위한 헤더

using namespace std;

int main() {
	string s = "1234567890";
	int num = stoi(s); // string to int

	cout << "num value: " << num << endl;
	cout << " num type: " << typeid(num).name() << endl;
	return 0;
}

 

2. int to string변환 / to_string() 함수

#include <iostream>
#include <string> // to_string() 함수 사용을 위한 헤더

using namespace std;

int main() {
	int num = 1234567890;
	string s = to_string(num); // int to string  

	cout << "s value: " << s << endl;
	cout << "s type: " << typeid(s).name() << endl;
	return 0;
}

+ Recent posts