How to set a date format in c++?

Hi all,
I am doing a school c++ project. I don't know how to solve one requirement which is the date that is entered by a user must be in this YYYYMMDD format and only the current year 2018 is valid. I can only use a string variable to store the date, please help.
First decide what you consider acceptable values.

Is "abcdefgh" acceptable? If not, why not?

How about "20189999"? If not, why not?

What about "20170801"?

Once you've decided what is, and is not, acceptable, you're half way there. Write out your tests for acceptable input.

Get the input from the user, as a string.

You can get the length of the string with the string::length() member function. http://www.cplusplus.com/reference/string/string/

You can check the value of each character in the string.

You can build substrings for testing out of the whole string.

Apply your tests. If any fail, the string is unacceptable.

Do it in small pieces. Write out your tests, and then start simply by taking a string input from the user.

http://www.cplusplus.com/doc/tutorial/basic_io/


Apply
Thanks.
Topic archived. No new replies allowed.