In the below code I am trying to parse 01/01/0000
this seems to give different results on different machines.
Is 01/01/0000 undefined behaviour in strptime implementation?
#include <iostream>
#include <sstream>
#include <ctime>
int main() {
struct tm tm{};
std::string s("01/01/0000");
if (strptime(s.c_str(), "%d/%m/%Y", &tm)) {
int d = tm.tm_mday,
m = tm.tm_mon + 1,
y = tm.tm_year + 1900;
std::cout << y << "-" << m << "-" << d << " "
<< tm.tm_hour << ":" << tm.tm_min;
}
}
On cpp.sh:
Code: link
Output: 1900-1-1 0:0
On Linux local machine:
Output is: 0-1-1 0:0
New contributor
Bharath Mourya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1