I have a simple structure which stores details of a person whose values needs to be initialized through user input. The structure is as follows :
typedef struct {
char name[20];
int age;
char address[50];
char vehicle[10];
}Runner;
I am using cin
to store the value of each Runner
but wish to take the inputs (that may contain whitespace in between) using enter key
after each value entered.
Below is the code :
Runner run1;
cout << "Enter name age address vehicle (pressing enter at each instance)" << endl;
cin >> run1.name >> run1.age >> run1.address >> run1.vehicle ;
It is quite evident that space separated values would be considered as two unique entries.
How do I skip the white-spaces and cin
only after enter is pressed. Also if there is another approach to such situations, it would be great to know the same.