Question: I have the following C++ code that is close to working. The program takes an input file in the format below. (int),(int),(int) (string) It generates

I have the following C++ code that is close to working. The program takes an input file in the format below.

(int),(int),(int)

(string)

It generates an output.txt file but for some reason mine is blank. How do I get this output.txt to display what I want it to? The rules I were following were as follows:

Your program should then sum the ints of each line and output the immediately following line's string, that many times, seperated by commas such that: 1,2,3 ham becomes: ham,ham,ham,ham,ham,ham

#include #include #include

int myAtoi(std::string str) { int result = 0;

for(int i=0; i< str.length(); ++i) result = result * 10 + str.at(i) - '0';

return result; }

int main() { std::fstream file1, file2; std::string word, filename1, filename2;

filename1 = "input.txt"; file1.open(filename1.c_str()); file2.open("output.txt",std::fstream::out);

for(int i=0; i<5; i++) { int sum = 0; file1 >> word; sum += myAtoi(word); file1 >> word; sum += myAtoi(word); file1 >> word; sum += myAtoi(word); file1 >> word; for(int j=0; j

file2 << " "; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!