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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -