0
string s;
cout<< "Enter name: ";
cin >> s;
cout<<"\n"<<s;

on running this i need:
Enter name: Tejesh Kinariwala
Tejesh Kinariwala

it is showing:
Enter name: Tejesh Kinariwala
Tejesh

so how to get the input till user hits return key, instead of breaking it at space

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by whotookmyname
0

Well string class is defined so that it stops on reading a space or newline so alternatively you can do this :

char s[20];
gets(s);
cout<<"\n"<<s;

This will read until it finds a \n' character and this will suffice your needs.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.