Get integers from a file into an array

Hey guys so basically I have to read numbers from a file and put them in an array. there are 50 numbers in the file.
I keep getting a weird number when I try to output the numbers in the screen.
for example lets say these numbers are in the file:
1 2 3 4 5
I want to read them as an array and out put the array in a screen this is how I think i should do it but im guessing im wrong any ideas would be great thank you!
int main (){
ifstream infile;

const int num=50;<---number of "numbers" im trying to read.
int list[num];<------name of the array.."infile.txt");
while (!infile.eof()){
for (int count = 0;count<=num;count++)
{ infile>>list[count];

Last edited on
How about you post your entire code with code tags ? That would help.
post the cout command
remove the while loop, you don't need it
for (int count = 0;count<=num;count++)
for (int count = 0;count<num;count++)
The reason for this is your starting counting from 0 not 1.
The other option is to change count =1
Last edited on
Hey sorry about that I dont know how to post tags :(
anyway thnx for taking the time.
once I do that for loop, should I do something like this?

for (int count = 0;count<num;count++)


Topic archived. No new replies allowed.