2

I know it is possible to use istringstream as an alternative to sscanf, for example:

std::istringstream argtime{"01:00"};
char colon;
int hour;
int minute;

argtime >> std::noskipws;
argtime >> hour >> colon >> minute;
if(argtime && colon == ':') // hh:mm is parsed successfully.
{
    // ...
}

The above lines are partly similar to the following sscanf code:

sscanf("01:00", "%d:%d", &hour, &minute);

But is there any solution to achieve the maximum field width feature of sscanf via istringstream in C++ (C++11/C++14/C++1z)?

sscanf("01:00", "%2d:%2d", &hour, &minute);

Edit: I also tried setw IO manipulator, but it does not work for integers.

Sadeq
  • 7,795
  • 4
  • 34
  • 45
  • Possible duplicate of http://stackoverflow.com/questions/2839592/equivalent-of-02d-with-stdstringstream – A.S.H Nov 10 '15 at 20:57
  • 1
    @A.S.H: No, it is not. I'm asking about Input Stream. – Sadeq Nov 10 '15 at 21:02
  • 1
    That's why I said ""Possible". To suggest you check that thread, iy might answer your question since there is much similarity in formatting stremas for input and for output. You might also have the limitations discussed there. – A.S.H Nov 10 '15 at 21:08

0 Answers0