Help using fstream- kinda lost

Pages: 12
Open the folder in the console and have a look at the files.
For some reason it might happen that a file ends with .txt.txt
Run this on your system. Give us the output.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()
{
   int count = 0, sum = 0, number;
   ifstream inputFile( "numbers.txt" );
   if ( inputFile )
   {
      while ( inputFile >> number )
      {
         count++;
         sum += number;
      }
      cout << "sum = " << sum << '\n';
      cout << "count = " << count << '\n';
      // When everything else works, add code for average here
   }
   else
   {
      cout << "Can't open input file. Contents of directory are:\n";
      system( "dir" );
   }
}
I ran what you told me and it says "volume in drive c is os"
"volume serial number is 184b-6cd1.
Directory of c:\users\chriv\……."
I'm not sure why but when I copy and pasted the exact code from Qt to code blocks my program did indeed run well, if anyone knows what the solution is that'd still b great for future references, thanks!
ChrisValvo wrote:
"volume serial number is 184b-6cd1.
Directory of c:\users\chriv\……."


Yes, you have to give ALL of that directory! Then we can see what the precise names of files in it are!

Otherwise, there's very little chance of helping you.
Topic archived. No new replies allowed.
Pages: 12