매번 헷갈린다..
1. include <sstream>
2. stringstream ss(넣을 문자열) 로 선언
3. 공백 or \n 은 무시해서 넣어줌.
1) whlie 로 계속 넣던가
string str = "123 4567 89";
stringstream ss(str);
int a;
while (ss >> a)
cout << a << " ";
//123 4567 89
2) 타입이 다를경우 아래처럼 넣으면 됨.
int main() {
string str = "12 T4\n567";
stringstream ss(str);
int num1;
char ch;
int num2;
string s;
ss >> num1>>ch>>num2>>s;
cout<<num1<<' '<<ch<<' '<<num2<<' '<<s;
}
// 12 T 4 567
'코테공부' 카테고리의 다른 글
다익스트라 알고리즘 (0) | 2022.11.04 |
---|---|
난쟁이마을 c++ (0) | 2022.09.20 |
erase, substr.. (0) | 2022.09.02 |
프로그래머스 입국심사 c++ (0) | 2022.09.01 |
순열 조합 (0) | 2022.08.30 |