2011-10-29 12 views
8

Dovrebbe essere facile per voi ragazzi .....Boost :: tokenizer separati da virgola (C++)

Sto giocando intorno con tokenizers utilizzando Boost e voglio creare un token che è separato da virgole. qui è il mio codice:

string s = "this is, , , a test"; 
boost::char_delimiters_separator<char> sep(","); 
boost::tokenizer<boost::char_delimiters_separator<char>>tok(s, sep); 


for(boost::tokenizer<>::iterator beg= tok.begin(); beg!=tok.end(); ++beg) 
{ 
    cout << *beg << "\n"; 
} 

L'output che voglio è:

This is 


a test 

Quello che sto ottenendo è:

This 
is 
, 
, 
, 
a 
test 

AGGIORNATO

+0

simile a questa domanda: Se ho 'questo è ,,, un test' e' cout << "<" << *beg << "> ";' modificato nel codice, come faccio ad ottenere stringhe vuote anche, come ' <><> '? –

risposta

Problemi correlati