Number Analysis program

I'm trying to write a program that asks a user for a file name, which contains a set of numbers. The program should should read the contents of the file into an array but I can't seem to correctly open the file. Can't someone tell me if i'm doing something wrong?

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
27
28
29
30
31
32
33
34
35
36
37
 #include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
    ifstream inputFile;
    string filename;
    const int NUM_PLACES = 10;
    double numbers[NUM_PLACES];
    int count = 0;

    cout << "Enter the filename: ";
    cin >> filename;

    inputFile.open(filename.c_str());

    if (!inputFile)
        cout << "Error opening data file\n";
    else
    {
        while (count < NUM_PLACES && inputFile >> numbers[count] )
            count++;
        inputFile.close();

    cout << "The numbers are\n";
    for (int place = 0; place < count; place++)
        {   cout << numbers + 1 << numbers[place] << endl;

        }
    }
    return 0;
}


Last edited on
Line 25 is in the wrong place
@SamualAdams, thats incorrect. the file should only be closed if it was opened successfully and after all reading is done. line 25 is the right place for it.

@OP
you need to explore the problem further, what error are you getting from inputFile when you try to open it? does the file really exist? is your program looking in the correct folder? perhaps line 20 should also output the error code so that you can look it up.

when you run the program try entering an absolute path to the test file and see if it finds it then.

line 20 should be outputting place+1 not numbers+1
I figured out that the problem was with the file name but now it just says "The numbers are"
now it has this error


LINK||fatal error LNK1181: cannot open input file 'obj\Debug\numbers.obj'|
Topic archived. No new replies allowed.