-
cin / scanf
Hi,
Can somebody please help me out?
Consider the following snippet:
cout << "Enter your name: ";
cin >> n;
cout << "Hello " << n << "!" << endl;
If I input 'Joe Bloggs' it will only print out 'Hello Joe!'.
When using cin or scanf to read a string, how do you make it read everything the user types in (including spaces)?
Thanks in advance.
-
-
using:
cin.getline>> name;
will assign all the strings on the line till it finds a new line character.
cin.get(givenName).get(familyName);
would be usefull if only two names, but u can add more to it.
-
yeah, the cin >> syntax's fields are delimited by spaces or endlines.