G
Generic Usenet Account
Sick and tired of the problems that cin was giving me in a menu-driven
CLI application, that accepts numerical inputs (I was getting into an
infinite loop when a non-numerical input was entered), I have gone
ahead and defined the following macro:
#define readStdin(x) while(true) \
{ \
cin >> x; \
if(!cin) \
{ \
cin.clear(); \
cin.ignore(MAX_LINE_LEN, '\n'); \
} \
else \
break; \
}
This macro has been working like a charm for me. Any other
suggestions are welcome. (Yes I know that I can read the line into a
buffer and read input from that buffer, but that's not what I want to
do).
Regards,
KP Bhat
CLI application, that accepts numerical inputs (I was getting into an
infinite loop when a non-numerical input was entered), I have gone
ahead and defined the following macro:
#define readStdin(x) while(true) \
{ \
cin >> x; \
if(!cin) \
{ \
cin.clear(); \
cin.ignore(MAX_LINE_LEN, '\n'); \
} \
else \
break; \
}
This macro has been working like a charm for me. Any other
suggestions are welcome. (Yes I know that I can read the line into a
buffer and read input from that buffer, but that's not what I want to
do).
Regards,
KP Bhat