I know I've asked but I'm now faced with a different problem. The last implementation went wrong since the number of chars on a given line is u known.


John 15 nmmo short brown hair look young
Andrew 22 young long bloack wavey hair with blue eyes.


I've tried getting fstream and string an d do:

file >> name >> age >> sname >> colour ....

but the problem is there isnt a set amound of words on a given line. So I thought of reading 1 char at a time

char ch = ' a'; // inistilise ch.

while((ch = file.get()) != EOF)

reads one ch at a time, my problem is storing the different chars as strings using the string class. but making sure ive got everything on that line in different strings.

How do I tell it when its hit a white space thats the end of 1 string start the next unless its a '\n' . If its a '\n' then call a function.

Cheers guys...

I would use getline() to read the entire line, then call string's find() method to locate the spaces.

std::string line;
while( getline(file,line) )
   while( line.length() > 0)
      std::string word;
      int pos = line.find(' ');
      if(pos > 0)
          word = line.substr(0,pos);
          line = line.substr(pos+1);
          word = line;
           line = "";