Code:
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
string nick;
cout<<"Enter your nick: ";
getline(cin, nick);
cout<<nick<<endl;
return 0;
} Or:
Code:
int main(int argc, char* argv[])
{
char nick[12];
cout<<"Enter your nick: ";
cin.getline(nick, 12, '\n' );
cout<<nick<<endl;
return 0;
} Observe the
cin.getline versus
getline.
The cin version is the
istream version. Use this when you work with C-style strings. Use getline
without "cin" for the
string type.