Question: I have the following C++ code for input/output type stuff. Could you please go through and just thoroughly put comments on what is happening throughout
I have the following C++ code for input/output type stuff. Could you please go through and just thoroughly put comments on what is happening throughout the program. Thanks!
#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
Get step-by-step solutions from verified subject matter experts
