用stringstream可以用来分割空格、tab、回车换行隔开的字符串:
#include
#include
#include
using namespace std;
int main() {
string str = "hello world sperated by spaces\tand\nhuiche";
vectorarr;
istringstream ss(str);
string word;
while(ss>>word) {
arr.push_back(word);
}
for(size_t i=0; icout << arr[i] << endl;
}
return 0;
}
什么环境?能用CString吗?如果能,就很简便