B
bgeneto
Hi!
Please consider the following C++ code fragment: (using <iostream> and
<string> standard libraries)
string s; int i;
cin >> i;
getline (cin, s);
Correct me if I'm wrong: In this first case cin reads data from the
input buffer until it finds a delimiter, leaving the delimiter
(newline) in the input (keyboard) buffer. After that, the getline
function reads that delimiter directly from the input buffer, thus
ending the input process, without asking for another string data.
Right? Now consider this code
string s; int i;
cin >> i;
cin >> s;
Again, the first cin reads data until it finds the delimiter, leaving
the delimiter in the input buffer. So, why the second cin requires new
data from the user if it finds the delimiter in the buffer?
Exactly in what aspect cin behave different from getline()?
Thanks in advance,
Bernhard Georg Enders.
Please consider the following C++ code fragment: (using <iostream> and
<string> standard libraries)
string s; int i;
cin >> i;
getline (cin, s);
Correct me if I'm wrong: In this first case cin reads data from the
input buffer until it finds a delimiter, leaving the delimiter
(newline) in the input (keyboard) buffer. After that, the getline
function reads that delimiter directly from the input buffer, thus
ending the input process, without asking for another string data.
Right? Now consider this code
string s; int i;
cin >> i;
cin >> s;
Again, the first cin reads data until it finds the delimiter, leaving
the delimiter in the input buffer. So, why the second cin requires new
data from the user if it finds the delimiter in the buffer?
Exactly in what aspect cin behave different from getline()?
Thanks in advance,
Bernhard Georg Enders.