Strings

5.3 - Substring


The substr(pos, len) method can be used to get the substring of a string starting at pos and spanning len characters.

std::string my_name("Jose Gonzales");

// Prints out "Jose".
std::cout << my_name.substr(0, 4) << std::endl;

// Prints out "Gonzales".
std::cout << my_name.substr(5, 8) << std::endl;

Task

Your task is to create a program which takes the a date in the MM/DD/YYYY format and convert it into the way superior YYYY-MM-DD format (ISO 8601).

Sample input

04/20/2020

Sample output

2020-04-20
#include <iostream> #include <string> int main() { }