c++ - fstream Reading numeric output from a file and outputting the sum to another file -
i trying read file in format of
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
Post a Comment