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
Do you want to use the fstream class ?
You can search for the fstream documentation in the microsoft web site : www.microsoft.com
You can search for the fstream documentation in the microsoft web site : www.microsoft.com
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."
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."
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.
I also agree with Clox, I also like using the good old C functions instead of the C++ classes.
Visit our homepage: www.rarebyte.de.st
GA
Visit our homepage: www.rarebyte.de.st
GA
Visit our homepage: www.rarebyte.de.stGA
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
ColdfireV
[email=jperegrine@customcall.com]ColdfireV[/email]
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
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
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;
--------------------
You are not a real programmer until you end all your sentences with semicolons;
Visit the ROAD Programming Website for more programming help.
--------------------
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
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
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
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement