Hi,
Can you help me? I stumbled upon this rather rudimentary behavior yet unable to explain why it happens. I hope someone here can help me unravel this:
For the code above, I use cin.get to obtain the value for 'address'; because of the newline character in queue, 'address' will get the newline character instead. Curiously, this will also skip over the acquisition of 's1' and 's1' as well. Moreover, if i replace: cin.get(address,90) withCode:#include <iostream> #include <string> using namespace std; int main() { string s1; string s2; int years; int months; char address[90]; cin >> years; cin >> months; cin.get(address,90); cout << "Enter string 1: "; cin >> s1; cout << "Enter string 2: "; cin >> s2; cout << s1 << endl; cout << s2 << endl; return 0; }
The program will not skip over 's1' and 's'2'. Why is that?Code:cin.getline(address,90)
Sincerely yours,



LinkBack URL
About LinkBacks



