-
stoi() - string to intC++ 2021. 7. 6. 03:29
string으로 입력 받은 숫자 int형으로 변환하고자 할 때 사용
string 헤더 파일로 include 가능
같은 방식으로 stof (string to float), stod (string to double) 등 사용 가능
#include<iostream> #include<string> using namespace std; int main(){ string a, b; cin >> a >> b; cout << "int a = "<< stoi(a) << ", " << "int b = "<< stoi(b) << endl; cout << "a*b = " << stoi(a) * stoi(b) << endl; }
12 3456789 int a = 12, int b = 3456789 a*b = 41481468
'C++' 카테고리의 다른 글
map (0) 2021.07.11 입출력 조작자 (Manipulator) (0) 2021.07.11 pair, vector (0) 2021.07.06 cin.ignore() - cin, getline 동시에 사용할 때 (0) 2021.07.06 stack (0) 2021.06.01