Help with errors on arrays?

Newbie here, right so I'm trying to get some integers from a text file and store them in a array. I have not been very successful as I keep on getting errors. I am not very good with arrays. I want to know what I'm doing wrong and how should I fix it.So in my text file I have 9 integers and Im trying to store it in the array. In the main File im trying to output one number in my array.

Here is the code I have in My header File

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
include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;

const char INPUT_FILE[9] = "numbers.txt";
const int NUM_ITEMS = 9;

void readList( int list[], int n)
{	
	ifstream inFile; 

	inFile.open("numbers.txt");
// Loop through the input file
	while ( !inFile.eof() )
	{

	inFile>> list[n];
	n++;	



}

}



And here is the code in my Main File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "header.h"
#include<cmath>
#include<string>

#include<iostream>
#include<fstream>
using namespace std;
void readList( int list[], int n);

int main()
{
	
	
	cout<<readList(list[2], 9);



system("pause");
return 0;
}
What are these errors?

error C2117: 'INPUT_FILE' : array bounds overflow
see declaration of 'INPUT_FILE'
: error C2065: 'list' : undeclared identifier
: error C2059: syntax error : ']'
Errors i spot:

Might be a copy and paste error but line 1 you forgot the '#' symbol.

you declare a const char* with 9 elements, lets count how many you declare:
1(N) 2(u) 2(m) 3(b) 4(e) 5(r) 6(s) 7(.) 8(t) 9(x) 10(t)
another way of writing const char INPUT_FILE[9] is const char * INPUT_FILE which is a pointer to char(array).

when opening the file you never used the const char array you set up, there is no reason to have the variable there.

You can open the file during the constructor to save time ifstream inFile("numbers.txt")

what happens if the text file contains 15 numbers? the array bounds would cause your program to crash. You need to use a for loop to read in number x(arr length) times.
Topic archived. No new replies allowed.