Fines in C++, ?
I learned this once but completely forgot. Could anyone be kind enough to tell me how I could open a file (of integers) and just read them so I can put them in an array. Thanks!
Depends on what set of file functions you want to use.. Personally, I use the C stream ones, lots of people like to use the fstream ones, or the lower level ones though. Here are some things to look up in your compiler documentation:
fopen (C streams)
ifsteam/ofstream (C++ streams)
_open (I think, lower level, OS file handle stuff)
CreateFile (Win32 functions)
fopen (C streams)
ifsteam/ofstream (C++ streams)
_open (I think, lower level, OS file handle stuff)
CreateFile (Win32 functions)
If you''ve got a file containing, say, 80 integers, you can always do this:
Or something like that.
-Ironblayde
Aeon Software
int numbers[80];FILE *file_ptr;if ((file_ptr = fopen("file.dat", "rb")) != NULL){ fread(numbers, 80, sizeof(int), file_ptr); fclose(file_ptr);}
Or something like that.
-Ironblayde
Aeon Software
"Your superior intellect is no match for our puny weapons!"
Here''s how you would do it with the C++ Streams:
Hope that helps
The road to success is always under construction
int integers[80];ofstream fOut;fOut.open("Filename.fil",ios::out | ios::binary);fOut.write((char*)ℤ,sizeof(integers));fOut.close();// And you would read it back with:ifstream fIn;fIn.open("Filename.fil",ios::in | ios::binary);fIn.read((char*)ℤ,sizeof(integers));fIn.close();
Hope that helps
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement