Morgan 201128374 4383745,12394 5455.30
drew 22223 91939,5324 55.9
stringstream strm;
sstream strm(s)
strm.str() return a copy of a string
strm.str(s) copies the string into strm return void.当我将变量赋值给Stringstream时,我正在寻找更多的函数。我怎么会忽略标点符号?我的书上只列出了这两种功能。
struct PersonInfo{
string name;
vector<string> numbers;
}
string line, word;
vector<PersonInfo> people;
while(getline(cin, line))
{
PersonInfo Info;
istringstream record(line);
record >> info.name;
while (record >> word)
info.numbers.push_back(word);
people.push_back(info);
}发布于 2015-08-03 09:53:21
我怎么会忽略标点符号?我的书上只列出了这两种功能。
使用std::getline,它接受分隔符参数:
if(! std::getline(record, line, ' ') ) // reads to first space
throw std::runtime_error{ "bad stream format" };您应该读入分隔符,并将分隔符替换为“”或“;”。
https://stackoverflow.com/questions/31784174
复制相似问题