생각보다 심플하고, 아주아주 유용할거같다
기능 : 띄어쓰기, \n 줄바꿈 이 두개를 구분하게 해주는 아주 유용한 함수~~
1) 해더에는 sstream
2) 필요한 인풋들
- 나누고 싶은 string
- 나눠진걸 결과에 담을 string 배열
- 옮겨담기용 string 하나, int index 하나
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string a = " gfd qwe asdd sdf sdf";
stringstream ss(a);
string result[5];
string token;
int index = 0;
while (ss >> token)
result[index++] = token;
for (int i = 0; i < 5; i++)
{
cout << result[i] << " ";
}
}