On 07/11/09 22:33, Maxim Yegorushkin wrote:
Not in C++. That's a Posix extension, so if you're concerned
with portability, you can't use it.
There are several solutions to what he wants to do, depending on
the context and how flexible he wants to be with regards to the
input (exactly two digits for the hour, or one or two digits,
etc.). Basically, however, I'd start by defining a
std::istream& operator>>(std::istream& source, time& dest)
function, using sgetc on the input to determine if the next
character was what I wanted. Depending on how flexible I wanted
to be, I might just read exactly eight characters, validate it
with a regular expression, then use an istringstream to convert
the three numbers; or I'd input a number, check for and extract
the ':', input another number, check for and extract the ':',
and input the third number.