Archived

This topic is now archived and is closed to further replies.

filereading in VC++

This topic is 6591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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......

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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')

Share this post


Link to post
Share on other sites