Thank's for the help, but still not working though.
I've changed my code to:
1 2 3 4 5 6 7
|
cout<<"Make: ";
cin.getline(make, 20);
cout<<"Year: ";
cin.getline(year,5);
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"Mileage: ";
mileage=get_int(0);
|
also I had to include <limits> header because my compiler was complaining about numeric_limits not beeing defined in the scope.
I never get a chance to input mileage, if I input a string larger than 4chars to year.
EDIT: I'm using Code Blocks with the standard compiler, if this helps.
EDIT2: Finally solved it.
changed my code to:
1 2 3 4 5 6 7 8
|
cout<<"Make: ";
cin.getline(make, 20);
cout<<"Year: ";
cin.getline(year,5);
cin.clear();
cin.sync();
cout<<"Mileage: ";
mileage=get_int(0);
|
Can you still explain me thought, why the first aprouch failled?
EDIT: I've discovered that this problem happens whenever I input something that goes out of the getline boundaries. So should I add cin.clear() and cin.sync() everytime I try to read a string with getline?
Is this the optimal way, or is there a more elegant approuch to it?
Sorry for all the questions but I'm just starting.