2015-08-03 76 views
0
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分配变量时正在寻找更多的函数。我将如何忽略标点符号?我的书只列出了上面的两个函数。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); 
} 
+0

http://www.cplusplus.com/reference/sstream/stringstream/ – Steephen

回答

0

我怎么会忽略标点符号?我的书只列出了上面的两个函数。

使用std ::函数getline,这需要在一个分离器的参数:

if(! std::getline(record, line, ' ')) // reads to first space 
    throw std::runtime_error{ "bad stream format" }; 

你应该阅读到分离器,和交替分离器是“”或“;”。