Click to See Complete Forum and Search --> : parsing with stringstream


blase
July 18th, 2003, 07:00 PM
I want to parse a date string MMDDYYYY using std::istringstream into three integers. But the following code does not work...

int month, day, year;
istringstream is("021791990"); //Feb 17, 1990
is >> setw(2) >> month;
is >> setw(2) >> day;
is >> setw(4) >> year;

This doesn't work, month gets the value of 2171990, I want it to be 2.
Is there an elegant way to make this work (without using sscanf()?)

BTW, I am using Visual studio .NET.

-Blase

Andreas Masur
July 18th, 2003, 07:14 PM
[Moved thread]