-1

My question is for example I have 3 variables;

int y, m ,d;

Is there anyway that I can take user input in the form of YYYY/MM/DD and store YYYY into y, MM into m, and DD into d by using std::istream functions?

Andy Lin
  • 116
  • 1
  • 9
  • `char dummy; std::cin >> y >> dummy >> m >> dummy >> d;`?? – user0042 Aug 10 '17 at 06:25
  • possible duplicate of https://stackoverflow.com/questions/7302996/changing-the-delimiter-for-cin-c and possibly even https://stackoverflow.com/questions/7297623/how-to-provide-your-own-delimeter-for-cin – Jerry Jeremiah Aug 10 '17 at 06:45
  • Possible duplicate of [changing the delimiter for cin (c++)](https://stackoverflow.com/questions/7302996/changing-the-delimiter-for-cin-c) – Caleth Aug 10 '17 at 08:54

1 Answers1

0

As far as I know, you can't specify a delimiter with >> you can use the following:

std::string input;
cin.getline(input, 4, '/');

Then you would convert that to int by doing: int years = std::stoi(input);

Andrew Smith
  • 37
  • 1
  • 10