need your help in getting user inputs.
I want users to type a string that has spaces.
i cant use cin>>variable as the space in between makes the problem go wrongly.
if i use getline(cin,string_variable) it works correctly. but i need to type twice in order to make it work proberly.
cout<<"Enter movie name";
getline(cin, mvName);
getline(cin, mvName);
Is there a better way to get user input than this or is there any other codes to type rather than typing the getline twice? Pls advice.
When switching between formatted input using
in >> valueand unformatted input, e.g., usingstd::getline(in, value)you need to make sure that you have consumed any whitespace you are not interest in. In you case there is probably a newline in the buffer from a prior input. Assuming you are nit interested in leading whitespace the easiest approach is to use something like this:BTW, you should always check that your input was successful.