【发布时间】:2010-01-22 17:19:04
【问题描述】:
std::stringstream convertor("Tom Scott 25");
std::string name;
int age;
convertor >> name >> age;
if(convertor.fail())
{
// it fails of course
}
我想将两个或多个单词提取到一个字符串变量中。到目前为止,我已经阅读,似乎这是不可能的。如果是这样,还有什么办法呢?我希望name 获取数字(年龄)之前的所有字符。
我觉得使用 sscanf 最舒服,但我显然不能。
例如,我需要能够提取age 之前的所有单词。
【问题讨论】:
标签: c++ string stringstream