Watch Anime | Mortgages | Credit Cards | Auto Loans | Loans
Help with file I/O in visual C/C++ [Archive] - PCMech Forums

PDA

View Full Version : Help with file I/O in visual C/C++


bigk376
10-24-2003, 02:45 AM
Hi,

For class I have to right a console application in visual c/c++ 6.0 that reads a text file stores the text file as an array of integers. Then the program has to perform a bottom-up heap construction on the array. I’ve figured out the bottom-up heap construction and the down heap bubbling. What I haven’t been able to do is figure out how to read this(http://www.utdallas.edu/~besp/CS3345/keys.txt (keys.txt)) txt file into an array of integers, none of the courses I’ve taken so far have covered this, and none of the books I have really show any insight on how to do this. If anyone could show me how to do this or give a hint... I’d really appreciate it.

Thanks,

bigk

doctorgonzo
10-24-2003, 09:31 AM
Have you written any code yet? If so, it would help if you posted it.

Also, your link is not working.

David14259
10-27-2003, 07:35 PM
You need to use the fstream.h library.

Here's some code I got from a program of mine...it should get you started:
ifstream in_file;
int i=0;
char inBuff, buffSize;
in_file.open("inventoryfile.txt");

in_file.getline(inBuff,buffSize);

in_file>>stock[i];

in_file>>price[i];

while(! in_file.eof())
{
i=i+1;
in_file.getline(inBuff,buffSize);

in_file>>stock[i];

in_file>>price[i];

}

in_file.close();