Reading Third Word of File Input (C++) -


so doing practice exam 1 of classes, i'm stuck how solve problem. given following c++ code:

#include <iostream> #include <fstream>  using namespace std; int main​() { ifstream infile("princes.txt"); string s;  while(________________) {     cout << s << endl; }     cout << endl;     return 0; } 

and ________ is, supposed fill in code generate desired output. not allowed modify code besides underscored area. file reading in called "princes.txt" , desired output are:

"princes.txt" prince of persia prince of wales prince of bel-air prince of egypt  desired output: persia wales bel-air egypt 

i'm stuck on how read third word of each line using underscored area. know how read whole line getline or 3 separate strings output third string each time, since we're not allowed modify else, i'm lost.

how about:

while(infile>>s && infile>>s  && infile>>s) 

which clobber first 2 s values?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -