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

    How to understand 2 main() functions after using uftrace to profile the C++ program? -

    c# - Update a combobox from a presenter (MVP) -

    How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -