problems with spaces... [Archive] - C Board

PDA

View Full Version : problems with spaces...


Unregistered
06-21-2002, 05:37 PM
At the moment i am making a game that requires reading from file and then outputting that. At the moment I cannot output anything after the first space in a line. For example:

char data[50];
fin>>data;
cout<<data;


Here is the file:

This is the data



here is what the program displays:

this



what can i do to fix this?

MrWizard
06-21-2002, 05:42 PM
Try fin.getline()

Unregistered
06-21-2002, 06:10 PM
Um... Thanx, but could you please tell me what to put IN the fin.getlin()? Becuase i looked it up and i couldnt make heads or tails of it.

MrWizard
06-21-2002, 09:10 PM
Sorry I was not more clear. Here is the prototype for the function:

istream& getline( char* pch, int nCount, char delim = '\n' );

So, you might say something like this...

fin.getline( data, 999, '\n' );

This says, store the information from file in the field "data" , second parameter is how many characters to read in, and the last parameter is the delimiter which defaults to newline or can be used if you want to stop when a certain character is reached.