Ok so I am looking to read in a bunch of different types of data for a program, but I am having trouble doing so in a very robust way.
For strings it's easy.
string temp;
getline(cin, temp);
Simple and quite robust.
For the rest I am having trouble reading in bad data... Example.
for doubles
cin >> elevation;
if (cin.peek() == '\n') {
cin.ignore();
}
This will read in all the data and ignore the new line char. But if the user enters a character themselves, the program crashes. Similarly with any data that I would use cin / fin(for input file stream).
Any tips would be greatly appreciated.