c++ - fstream Reading numeric output from a file and outputting the sum to another file -


i trying read file in format of

  • gerry $300
  • thom $500
  • gus $700
  • and attempting output total amount of money file.

    how go this? appreciated!

    define input file stream , open file

    ifstream file("file directory"); 

    now we'll read line line need string save each line

    string line; 

    getline function return false when reaches end of file

    while(getline(file,line)){            // can use string stream divide string according spaces           istringstream ss(line); //now contains line           string word;            //now every time ss>>word next word after space can make loop , stop @ index of word u  while(ss>>word){ //some code stop when find word    } 

    } make variable , keep adding numbers , print output file stream


    Comments

    Popular posts from this blog

    javascript - Confirm a form & display message if form is valid with JQuery -

    Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

    ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -