View Single Post
Old 05-21-2004, 03:58 PM   #1 (permalink)
~Relentless~
Registered User
 
Join Date: May 2004
Posts: 4
~Relentless~ is on a distinguished road
Question getline-command not working properly???

Hi, I'm new in this forum, and I have been programming in C++ for about ½ a year or so... I am currently developing a console game, in which I wish for the player to be able to write a nick that may include spaces (whitespaces)... So I looked through the net to find a solution to my problem, as this cannot be done with the standard cin-command... I stumbled upon the getline(cin, string) command, and used it in my code; however, it seems to screw up everything. I am using the Microsoft Visual C++ compiler, and the code I am trying to get to work looks like this:

Code:
header("\t\t\tRelentless Faith - Role-Playing Game\n\n\t\t\tCharacter creation - Identity");
write("Before you may start the game you have to create you 
character.\nThis will only take a few moments, remember, that you 
can at any time in the game type \"help\", \"exit\" or \"restart\". 
\n\nNow just follow the instructions point by point.\n\nFirst of 
all, you need to decide what you will be known as during the 
game.\n\nWrite the name you wish to be known by here (may not 
contain any spaces): \n",8);

getline(cin, charnick);

write("\nYou will henceforth be known as: ",15);
	
write(charnick,15);

write("\n\nNow to the next step in creating your character...",15);

anykey();

gender();
I've included the necessary libraries, and defined the string variable earlier in the code. Don't mind the write()- and header() functions, they are simply just outputs of the text defined in the first parameter... So, my problem is, as mentioned, the getline function, that just won't seem to work properly... If you have any suggestions I'd be very thankful :)...

Last edited by ~Relentless~; 05-22-2004 at 03:03 PM.
~Relentless~ is offline   Reply With Quote