Am i missing something?

it's not compiling but i'm not spotting the bug. it is a simple code but i don't know if i am missing a small detail.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    ifstream inputfile;
    int number;
    int total = 0;
    inputfile.open("C:\Users\Caitlyn\Desktop\42.txt");
    while(inputfile >> numbers)
    {
          total+=numbers;
          }
          inputFile.close();
          cout << "total is: " << total << endl;
          system("pause");
          return 0;
          }
1) You need to escape all of your backslashes. (Remember, backslash is a special character in strings)
So it should be
inputfile.open("C:\\Users\\Caitlyn\\Desktop\\42.txt");

2) You haven't declared the numbers variable (line 10, 12). Did you mean to put number?

3) Line 14: it should be inputfile, not inputFile.

4) It might work for your compiler without it, but technically, to use system(), you need to #include <cstdlib> . Either way, it's generally not recommended to use that function anyways. Here's why: http://www.cplusplus.com/forum/articles/11153/

Tip: Actually read all of your compiler errors. They'll usually help you pinpoint where the errors in your code are coming from.
Last edited on
Topic archived. No new replies allowed.