Computing.Net > Forums > Programming > c++ read file into array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

c++ read file into array

Reply to Message Icon

Name: awires
Date: March 23, 2004 at 01:05:57 Pacific
OS: windows xp
CPU/Ram: p4 2.8 ghz/512
Comment:

Im trying to read a file containing numbers.
ex: 1 2 3 4 5

i open the file. make sure its opened properly and try to read the data into an array with code:

void clsArray::read_ary()
{
int temp;

Randoms >> temp;

while ((!Randoms.eof()) && intCount < MAX)
{intArray[intCount] = temp;
cout << intArray[intCount] << " ";
intCount++;
Randoms >> temp;
}
}
the file is opened in the constructor and called Randoms.
When the program initializes it prints out 0. as if the file is eof after the first time through the while loop. any ideas why?

Adam



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: March 23, 2004 at 05:43:40 Pacific
Reply:

Was intCount set to 0 somewhere??


0

Response Number 2
Name: awires
Date: March 23, 2004 at 09:13:40 Pacific
Reply:

yes it was.

Adam


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


sending a pro through com... Batch file that can do ma...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c++ read file into array

Print multiple files into array www.computing.net/answers/programming/print-multiple-files-into-array/18284.html

C arrays of strings from a file www.computing.net/answers/programming/c-arrays-of-strings-from-a-file/14025.html

read data from a file into an array www.computing.net/answers/programming/read-data-from-a-file-into-an-array/11140.html