title: C++ trying to calculate total from input file
body: <p>My project is to read an input file with a set of integers (I do not know how many), calculate the total of those integers, then create an output file and write the total on the output file.</p>
  
  <p><strong>Everything in my code works except the total I get from the output file is not actually the total that I'm trying to calculate.</strong> </p>
  
  <p>For example, the integers contained on my testfile1 document are: 14, 9, 12, -6, -30, 8, 109</p>
  
  <p>The number I'm getting on my sum document reads 28, which is clearly not the total of these integers.</p>
  
  <p>Here is my code.  I know some parts are redundant or not as simple as c++ could be, but I tried to format it according to what I have learned so far from my textbook, so some of it might not be as advanced.  Certain line numbers are missing because I took out the description blocks.
  <strong>I really just need to figure out why the total is not adding correctly (lines 33-38)</strong>.  Any help would be greatly appreciated.  </p>
  
  <p><strong>Thank you all so much in advanced!</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main() {
  
     ifstream inputFile;
     ofstream outputFile;
     string testfile1;
     string sum;
     int total=0;
     int num;
  
     cout &lt;&lt; "Please input name of file." &lt;&lt; endl;
     getline (cin, testfile1);
  
     inputFile.open(testfile1.c_str());
  
     if(inputFile) {
        while(inputFile &gt;&gt; num){
           total=+num;
        }
        inputFile.close();
     }
     else {
        cout &lt;&lt; "could not access testfile1" &lt;&lt; endl;
     }
     outputFile.open("sum");
  
     if(outputFile) {
        outputFile &lt;&lt; total &lt;&lt; endl;
        outputFile.close();
     }
     else {
        cout &lt;&lt; "could not access file." &lt;&lt; endl;
     }
  
     return 0;
  }
  </code></pre>