🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

filereading in VC++

Started by
7 comments, last by bosjoh 24 years, 7 months ago
You could use different methods there. if you are using MFC, you might want to use Archive and CFile.
In other things you can read files the same way as in the ol' DOS days.

------------------
Dance with me......

Advertisement
Here's something like what i use. First off, you open the file "name", then get the length of the file, then read "length" bytes into the buffer. I'm not sure that any of the functions listed are in the correct format...I may have left out some parameters or something(check your documentation for the exact usage).

char * name = "c:\autoexec.bat";
long handle = NULL;
long length = NULL;
unsigned char * buffer = NULL;

handle = open(name);
length = getlength(handle);
read(handle, buffer, length);

------------------
When life hands you lemons, throw them at God's head.

WIN32 based applications should use:

CreateFile - to open a file
ReadFile/Ex - to read from a file
WriteFile/Ex - to write to a file
CloseHandle - to close a file

VirtualNext

VirtualNext has the best general way to use Win32 files. The only time you want to use a different system is when you are writing cross platform code - then use either the C runtime library functions (which will probably use the Win32 calls in their own implementation) or the C++ fstream classes (which also might use Win32 calls internally). I personally use fstream for all of the classes I write, unless they are directly using other windows only code...that way I can port them just by recompiling for a different target. I guess CFile is just as good s direct API calls if you are only targeting Win32, but i've never used it myself so I'm not sure.

[This message has been edited by Xai (edited November 30, 1999).]

a better thing to use than fstream is the good old fopen, fgets, fputs, etc. They allow appending to a file and many other useful and cool options not found in fstream.
--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Actually, I'm pretty sure you can do anything with fstream and related classes that can be done with the standard C file I/O library, and probably more.
Whoa!
A lot of replies allovasudden (quoted from FF7).
I've found my answer already (I use fstream).

Thanx

Maybe a silly question but how do you read from a file in VC++? (maybe fstream?)
Just something to think about, using C file functions doesn't necessarily make your files cross-platform. Motorola chips store the bytes in a different order than Intel, so if you try and pull in anything bigger than sizof(BYTE) you need to start flipping MSB/LSB, and I don't think the C functions correct for this (since neither way is really 'correct')
-the logistical one-http://members.bellatlantic.net/~olsongt

This topic is closed to new replies.

Advertisement