c++ - How does ifstream know where is the delimeter -


so when readfile("animal.txt") gave me

zebra baboon orangutan gorilla aardvark lion tiger cougar ocelot panther rat mouse gerbil hamster elephant rhinoceros hippopotamus 

i know how ist >> s identify delimiter , separate long string individual words. provided txt , implementation below .

animal.txt   zebrababoonorangutangorillaaardvarkliontigercougarocelotpantherratmousegerbilhamsterelephantrhinoceroshippopotamus 

and

sortedlist readfile(string infile) {       sortedlist result;       string s;        ifstream ist(infile.c_str()); // open file       // check if file opened correctly       if(ist.fail()) throw runtime_error("file not found");        // read file list       while(ist >> s){           cout<< s << endl;           cout << ist << endl;             result.insert(s);       }        return result; } 

the operator>> when applied stream on left , string on right.

will read "white space" separated word stream string.

mote precisely will:

  1. read , ignore characters until issapce() false.
  2. read , store in string characters until isspace() true.

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -