get_time is part of the localization library and is impacted by things like locale. Out of curiosity what does the runtime say the output is for the time you believe to be invalid?
What is the version of the C++ language your code is compiling for?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
As part of input validation, I'm using std::get_time() to validate the input date that is coming in to my application.
I'm assuming below logic should set fail bit due to incorrect format but that doesn't. So, what could be the problem?
I'm using Visual studio 2019.
This is the sample code.
int main() {
std::tm timeInfo;
std::memset(&timeInfo, 0, sizeof(timeInfo));
timeInfo.tm_isdst = -1;
std::istringstream ss("2021/12/31");
ss >> std::get_time(&timeInfo, "%m/%d/%Y");
if (ss.fail() == true)
cout << "fail bit is set"<<endl;
return 0;
}
get_time is part of the localization library and is impacted by things like locale. Out of curiosity what does the runtime say the output is for the time you believe to be invalid?
What is the version of the C++ language your code is compiling for?