完整代码:
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
std::string strip(std::string in) {
in.erase(std::remove_if(in.begin(), in.end(), [] (std::string::value_type ch)
{ return isspace(ch); }
), in.end());
return in;
}
int main() {
vector<string> strings;
istringstream f("50, -1.39626, -2.61799, -1.39626, -1.22173");
string s;
while (getline(f, s, ',')) {
cout << strip(s) << endl;
strings.push_back(s);
}
}
运行结果:
50
-1.39626
-2.61799
-1.39626
-1.22173
Press <RETURN> to close this window...