首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >stringStream函数

stringStream函数
EN

Stack Overflow用户
提问于 2015-08-03 09:44:46
回答 1查看 253关注 0票数 0
代码语言:javascript
复制
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时,我正在寻找更多的函数。我怎么会忽略标点符号?我的书上只列出了这两种功能。

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-03 09:53:21

我怎么会忽略标点符号?我的书上只列出了这两种功能。

使用std::getline,它接受分隔符参数:

代码语言:javascript
复制
if(! std::getline(record, line, ' ') ) // reads to first space
    throw std::runtime_error{ "bad stream format" };

您应该读入分隔符,并将分隔符替换为“”或“;”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31784174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档