1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//Note: The following code requires a compiler with C++ 11 support
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main()
{
string months[] = {"January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November", "December"};
string dateString;
regex dRegex("([0][1-9]|[1][0-2])/([0-2][0-9]|[3][0-1])/\\d{4}");
cout << "Enter a date in the form mm/dd/yyyy: ";
cin >> dateString;
if(!regex_match(dateString, dRegex))
{
cout << "Invalid input!" << endl;
return 1;
}
string month = months[stoi(dateString.substr(0,2))-1];
string day = dateString.substr(3,2);
string year = dateString.substr(6,4);
cout << "Output: "+month+" "+day+", "+year << endl;
return 0;
}
|