change the default separator in stream operator ">>" ?!?!?

F

Francesco

Hi,

I've a question...
is it possible to change the default separator in the stream operator ">>"
(for example from the blank space " " to the comma "," ) ?
Here is an example...

I want to read a sequence separated by blank space. I can do like
this...(with cin, but with file is the same thing)

2003/08/15 25 26 24.23232323
----------------------------------------
std::string data;
int val1, val2;
float r1;

std::cout << "Insert data: ";
std::cin >> name >> val1 >> val2 >> r1;
------------------------------------------

But if I've comma separated values like....????

2003/08/15,25,26,24.23232323

I know that I can use the getline where it's possible to select the
separator, but my question is only about the ">>".
With all values different from char or string I can di something like
this...

char c;
cin >> val1 >> c >> val2 >> c >> r1;

but with a string.... I don't know.
Thanks for your opinions,
Ciao, Checco.
 
F

Francesco

Yes, I know, but I need full portability and I must use only standard
library.
But it's not so hard to take tokens...

std::vector<std::string> scomponi(std::string str, char separatore)
{
// assegnamento della stringa al tipo stringstream std::stringstream
dati(str); std::string buff;
std::vector<std::string> ris;

// divisione in tokens
while (getline(dati, buff, separatore))
ris.push_back(buff);
return ris;
}

Thanks.
Ciao, Checco.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top