I can write a function to parse the string date, but I feel like I am re-inventing the wheel here. Is there a faster, perhaps built in C++ way to get from a string date of this format: 1/4/2000 to a more easy to use int like 20000104?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unless you need your built-in C++ way to do validation as well, the “obvious” parse is:
You can use stream extractors instead of
sscanfif you wantto write several lines of codetype safety.There’s certainly nothing in the standard library to do the
10000 * year + 100 * month + dayfor you. If you’re not wedded to that exact value, you just want an integer in the correct order, then you could look at whether your platform has a function to tell you the so-called “Julian day”.