Jump to content
  • Advertisement

Archived

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

Strife

fstreams

This topic is 6919 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

Okay, I''ve kind of hit a small problem: I''ve almost completely forgotten how to use file stream stuff in C++. I remember how to get input and send output with >> and <<, but I don''t remember how to use certain functions. Does anyone know of a good (preferably online) reference that will show me all the functions and how they are used? If you code it, they will come... Commander M http://commanderm.8m.com cmndrm@commanderm.8m.com

Share this post


Link to post
Share on other sites
Advertisement
Do you want to use the fstream class ?
You can search for the fstream documentation in the microsoft web site : www.microsoft.com

Share this post


Link to post
Share on other sites
I''m personally addicted to the file i/o declared in [stdio.h]. Here''s briefly how to use it...
FILE *fp; /* This creates a file descriptor */
fp = fopen("FILENAME", "RWA"); /* r=read w=write a=append */
/* you can add a + to the end of read to get read/write, or a + at the end of w to get write/read */
fclose(fp); /* Close the stream */
fprintf(fp, "hi"); /* Just like printf, just put the file descriptor as the first argument */
fscanf(fp, "%i", &digit); /* Same as scanf, just use descriptor as first argument. */

Hope that helped some - maybe you can make some since out of that little tutorial . remember, include stdio.h!!!!

"When people tell you they want to hear the truth, you know that their lying."

Share this post


Link to post
Share on other sites
Hey Cloxs, I agree that the C functions are better for more complex things, when converting variables and that kinda stuff(like sprintf). But for simple input/output from/to files, fstream is MUCH simpler, just my opinion.

Share this post


Link to post
Share on other sites
I wrote a complete article on how to do complete file I/O using fstream, but GameDev doesn''t seem to want to publish it. Go figure... I seems the more people that ask about this question, the more likely they''d put it up, but hey, that''s them.


ColdfireV

Share this post


Link to post
Share on other sites
Please give them a little time... all of the staff either have full-time jobs or are in college full time, many have both the job and the college thing going, and several of them have families. If it''s been a very long time you might ask Dave and see if it didn''t actually get submitted... but there are forum issues and other things they also need to deal with.

-fel

Share this post


Link to post
Share on other sites
So gamedev is run by a bunch of college students? Haha... I knew it all the time!

--------------------


You are not a real programmer until you end all your sentences with semicolons;

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

Share this post


Link to post
Share on other sites
kunta, that''s exactly what I want. I''ll take a look there later. Cloxs, Esap, I agree, but I''m just simply writing and reading, nothing too complex (just to save high scores), so I''ll probably just stick with ifstream and ofstream, but I''ll keep that in mind. Thanks.

If you code it, they will come...

Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com

Share this post


Link to post
Share on other sites
I absolutely do NOT agree that the C file I/O functions are better, ESPECIALLY for complex things. I don''t want to get into a C vs. C++ religious war, because in fact I still sometimes use C methods instead of C++, but almost always due to poor compiler implementation on the C++ library, not because the C system is easier or better.

Here are some leading questions.

1. Have you ever used the stringstream (or strstream) classes to format output (replaces the need for sscanf)?

2. Have you ever written your own (useful) i/o manipulators?

3. Have you read any or all of the GOF book "Design Patterns", or a similar book on object oriented design techniques?

If you have answered yes to ANY of the above, then I would like to hear more detail on what it is about the C versions you like better (because I might simply not know them well enough). Also, if you answered no, but you have a particularly good example of a place where the C versions definately exceed the C++ system in either ability or ease-of-use, please post it. I am always looking into the issues of what types of programming techniques work (in the real world, not academia) and which ones are either too hard, too convoluted, too slow, or just plain unneeded, and I think the C vs. C++ i/o system is a good area to look at for examples.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!