This is a question about invalid input, not invalid formatting. For example given the following code:
tm bar;
foo >> get_time(&bar, "%Y-%m-%d");
cout >> bar.tm_year >> bar.tm_mon >> bar.tm_mday >> endl;
This is fine if I define: stringstream foo("2001-02-28 non-leap year");
And has a clear error if I have invalid format such as: stringstream foo("bad format 2001-02-28 non-leap year");
But I don't know how to detect if my input was invalid for example:
stringstream foo("2001-02-30 non-leap year");
In this case bar
can be read as though nothing was wrong. Is there something I can listen for which will alert me that the input was invalid?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…