text to array

Hello Im trying to send these text intergers into my array
the Numbers are: 9 -3 45 -90 400 -20 -123 -67 98.

I am having alot of difficulty trying to do this. this is the code I have right now. I just cannot think of a way on how to read the numbers from the text file. I think I need to use a for loop but, how should I do it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>

using namespace std;

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

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

	inFile.open("INPUT_FILE");
	
	


	inFile.close();



}
Last edited on
1
2
3
for(int i = 0; i < /*number of characters here*/; i++){
infile >> mynumbers[i]; 
}
this will not include white space. and could i suggest integers to use if you are only using numbers. making it a char array will make it harder to manipulate the numbers.
will this for loop get all the numbers I want and store them in the array?

1
2
3
4
5
6
for( int i = 0; i < 50; i++)
{

infile.open>>mynumbers[i];

}
it will get 50 numbers. you could also try
1
2
int i = 0; 
while(infile >> mynumbers[i++]) 

do not do infile.open by the way. .open will open the file not get info from the file.
Topic archived. No new replies allowed.