- #1
RuthKom
- 2
- 0
I'm a beginner and currently learning programming by myself. when I read a book I came across an example which I don't quite understand.
I know that space terminates the input when the first "cin>>string1" statement is executed, but I don't know why the second "cin>>string1" reads "there"...can anyone tell me the reason behind?
Please help me...Thanks very much:)
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char string1[ 20 ]; // reserves 20 characters
char string2[] = "string literal"; // reserves 15 characters
// read string from user into array string2
cout << "Enter the string \"hello there\": ";
[B] cin >> string1; // reads "hello" [/B]
cout<< "\nstring1 is: " <<string1<<endl;
[B]cin >> string1; // reads "there"[/B]
cout << "\nstring1 is: " << string1 << endl;
return 0;
}
I know that space terminates the input when the first "cin>>string1" statement is executed, but I don't know why the second "cin>>string1" reads "there"...can anyone tell me the reason behind?
Please help me...Thanks very much:)