View Single Post
Old 05-21-2004, 07:44 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote