Re: why cin.get work here??
In the first case, you use getline(). getline() processes input until a '\n'
is encountered. So after entering the year (followed by return), the '\n'
is still in the input stream buffer, so addess ends up empty (as you observed).
In the second case, you are using operator >> ... By default, operator >>
ignores whitespaces, so the fact that the '\n' is still in the input buffer
stream is not relevant.
Re: why cin.get work here??
Quote:
Originally Posted by
Philip Nicoletti
In the first case, you use getline(). getline() processes input until a '\n'
is encountered. So after entering the year (followed by return), the '\n'
is still in the input stream buffer, so addess ends up empty (as you observed).
In the second case, you are using operator >> ... By default, operator >>
ignores whitespaces, so the fact that the '\n' is still in the input buffer
stream is not relevant.
so you mean if we get very next input by >>(after cin.getline) operator then no such probem will appear..
Re: why cin.get work here??
Quote:
Originally Posted by vkash
so you mean if we get very next input by >>(after cin.getline) operator then no such probem will appear..
In general, yes. Consequently, one method to avoid this kind of problem is to read line by line into strings, then parse the line, e.g., with the help of a stringstream.