Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions