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

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.

Use getline:

string s;
cout << "Enter some text: ";
getline(cin, s);
cout << "You typed: " << s << endl;

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.