字符串流函数
stringStream functions
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);
}
How would I ignore punctuation mark? My book only listed those two function above.
使用 std::getline,它接受一个分隔符参数:
if(! std::getline(record, line, ' ') ) // reads to first space
throw std::runtime_error{ "bad stream format" };
您应该阅读一个分隔符,并将分隔符替换为“”或“;”。
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);
}
How would I ignore punctuation mark? My book only listed those two function above.
使用 std::getline,它接受一个分隔符参数:
if(! std::getline(record, line, ' ') ) // reads to first space
throw std::runtime_error{ "bad stream format" };
您应该阅读一个分隔符,并将分隔符替换为“”或“;”。