    #include <iostream>    #include <fstream>     #include <string>    using namespace std;    int main()    {        //This declares the input and output files.        ifstream input;        ofstream output;        string filename;        int value, total = 0;        cout << Enter the file name:  << endl;        cin >> filename;        //This function opens file.        input.open(filename.c_str());       //This checks to see if the file can be opened,        //if yes, then it will calculate sum.       if(input)       {          while(!input.eof())              {                input >> value;                      total += value;             }       }       //This closes the input file.       input.close();      //This opens the output file.       output.open(sum.txt);     //This is where a file will open and the calculated sum will be shown.     if(output.is_open())     output << total;     //This is if the file can not be opened.     else        cout << Could not access the file. << endl;    //This closes the output file.    output.close();   return 0;   }The comment I received back about my code:There's a minor bug in fileAdder where the last value to be read is being added twice. It appears that this is an issue with text files in Linux/Unix ending with a newline. To fix it, I tried changing:int value, total = 0; into:int value; // value is some positive number nint total = 0; // total holds the sum of the first n positive numbersint number; // the amount of numbers
A program that asks user for file name and opens it - what did I do wrong?
c++