如题所述
第1个回答 2017-02-28
用stringstream可以用来分割空格、tab、回车换行隔开的字符串:
#include <iostream>#include <sstream>
#include <vector>
using namespace std;
int main() {
string str = "hello world sperated by spaces\tand\nhuiche";
vector<string> arr;
istringstream ss(str);
string word;
while(ss>>word) {
arr.push_back(word);
}
for(size_t i=0; i<arr.size(); i++) {
cout << arr[i] << endl;
}
return 0;
}本回答被提问者和网友采纳
第2个回答 2017-02-27
什么环境?能用CString吗?如果能,就很简便