Jump to content

  • Log In with Google      Sign In   
  • Create Account


filereading in VC++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 bosjoh   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 01:22 PM

Maybe a silly question but how do you read from a file in VC++? (maybe fstream?)

Sponsor:

#2 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 November 1999 - 08:39 AM

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


#3 asmLOCK   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 November 1999 - 07:00 AM

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.


#4 VirtualNext   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 November 1999 - 10:51 PM

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


#5 Xai   Crossbones+   -  Reputation: 1328

Like
Likes
Like

Posted 30 November 1999 - 12:32 AM

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


#6 Yanroy   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 03:07 AM

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.

#7 Dave Astle   Senior Staff   -  Reputation: 2305

Like
Likes
Like

Posted 30 November 1999 - 04:32 AM

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.

#8 bosjoh   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 08:13 AM

Whoa!
A lot of replies allovasudden (quoted from FF7).
I've found my answer already (I use fstream).

Thanx


#9 logistix   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 01:22 PM

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')




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS