| | |
fstream Tutorial
![]() |
•
•
Join Date: Jun 2005
Posts: 1
Reputation:
Solved Threads: 0
Hi. I'm writing a pong game which loads and saves a playlist and a configuration file. Both files load properly, but the playlist wont save properly. I think the problem may have to do with the fact that it uses either Win32, openGL, or fmod, but im not sure which. When I write a console application, it runs fine. I use the visual c++ 6.0 standard edition compiler.
this works:
void SaveConfig()
{
ofstream fout("tpong.cfg"); fout << volume <<endl; //volume is an int
fout <<stream<<endl; //stream is a bool
fout <<maxPoints<<endl; //maxPoints is an int
}
this doesn't work:
void SavePlaylist()
{
ofstream fout("tpong.pl");
fout<<numSongs<<endl; //numSongs is an int
fout<<playlist.c_str()<<endl; //playlist is a string
}
both are called on after the other. Changing the order of calling them doesn't have any effect. After the program runs, and these functions are called, "tpong.cfg" is changed while "tpong.pl" isnt.
Any help would be much appreciated.
this works:
void SaveConfig()
{
ofstream fout("tpong.cfg"); fout << volume <<endl; //volume is an int
fout <<stream<<endl; //stream is a bool
fout <<maxPoints<<endl; //maxPoints is an int
}
this doesn't work:
void SavePlaylist()
{
ofstream fout("tpong.pl");
fout<<numSongs<<endl; //numSongs is an int
fout<<playlist.c_str()<<endl; //playlist is a string
}
both are called on after the other. Changing the order of calling them doesn't have any effect. After the program runs, and these functions are called, "tpong.cfg" is changed while "tpong.pl" isnt.
Any help would be much appreciated.
•
•
•
•
Originally Posted by Ancient Dragon
you should probably update your tutorial to use current c++ standards -- The information is very very old and many of it obsolete. This makes it pretty difficult for new c++ programmers to weed through the chaff to get to the good stuff.
Only recently that the support for STL and standard C++ has become mainstream and found it's way into schools and other educational institutes.
Amazing is it not, education always gives you the old stuff and when you step out into the real world, you find so many new things and much more advanced concepts in practical use. Never be stuck with what you get in school. The net is the best place to get to know what goes on in the real world.
And me, well I was inactive here for a long time. I've travelled a lot further, learnt so much that I never even knew existed ..... and got a new monster of a comp

Write an update?
Good idea, I will see what I can do

http://xlock.fusionxhost.com
•
•
•
•
Originally Posted by lntrovertido
Hi. I'm writing a pong game which loads and saves a playlist and a configuration file. Both files load properly, but the playlist wont save properly. I think the problem may have to do with the fact that it uses either Win32, openGL, or fmod, but im not sure which. When I write a console application, it runs fine. I use the visual c++ 6.0 standard edition compiler.
this works:
void SaveConfig()
{
ofstream fout("tpong.cfg"); fout << volume <<endl; //volume is an int
fout <<stream<<endl; //stream is a bool
fout <<maxPoints<<endl; //maxPoints is an int
}
this doesn't work:
void SavePlaylist()
{
ofstream fout("tpong.pl");
fout<<numSongs<<endl; //numSongs is an int
fout<<playlist.c_str()<<endl; //playlist is a string
}
both are called on after the other. Changing the order of calling them doesn't have any effect. After the program runs, and these functions are called, "tpong.cfg" is changed while "tpong.pl" isnt.
Any help would be much appreciated.
Or does your program open 'tpong.pl' elsewhere and does not close it?
Try checking with fout.good() to see if the file has been opened properly.
Ok I realize I'm bumping a four year old thread, but the reason is to clarify for anyone who get here by googleing for "fstream tutorial". The tutorial above is somewhat obsolete now -- such as using #include <fstream.h> should now be #include <fstream> without the .h extension.
The OP -- FireNet -- also posted a link to updated code -- that link no longer exists.
The OP -- FireNet -- also posted a link to updated code -- that link no longer exists.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: C++ Style
- Next Thread: write aprogramme
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ cdialogbar char class classes code coding compile console conversion convert count delete deploy desktop developer directshow dissertations dll double-linkedlist download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loan loop looping loops map math matrix memory multiple news node number online output pagerank pointer problem program programming project python random read recursion recursive reference risk rpg string strings superclass temperature template test text text-file tree tutorial url validator variable vector video win32 windows winsock wordfrequency wxwidgets






