Coding Test/C++ 줍줍
[c++ 줍줍] string 공백 기준으로 잘라서 새 배열에 저장
seoyamin
2022. 5. 22. 00:38
▷ 문제 상황
string을 공백 기준으로 잘라서 새 배열에 저장하는 방법
ex) "Happy birthday to you" → A[ ] = { "Happy", "birthday", "to", "you" }
▶▶ 해결 방법
sstream 라이브러리의 stringstream 이용하기
#include <sstream>
int main() {
string s1 = "Happy birth day to you";
stringstream A(s1);
A.str(s1);
string item;
while(A >> item) {
cout << item;
}
return 0;
}