943,843 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 258380
  • C++ RSS
You are currently viewing page 5 of this multi-page discussion thread; Jump to the first page
Jun 1st, 2005
0

Re: fstream Tutorial

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:

C++ Syntax (Toggle Plain Text)
  1. void SaveConfig()
  2. {
  3. ofstream fout("tpong.cfg"); fout << volume <<endl; //volume is an int
  4. fout <<stream<<endl; //stream is a bool
  5. fout <<maxPoints<<endl; //maxPoints is an int
  6. }

this doesn't work:

C++ Syntax (Toggle Plain Text)
  1. void SavePlaylist()
  2. {
  3. ofstream fout("tpong.pl");
  4. fout<<numSongs<<endl; //numSongs is an int
  5. fout<<playlist.c_str()<<endl; //playlist is a string
  6. }

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.
Last edited by Nick Evan; Feb 25th, 2010 at 4:56 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lntrovertido is offline Offline
1 posts
since Jun 2005
Aug 16th, 2005
0

Re: fstream Tutorial

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Dec 16th, 2005
0

Re: fstream Tutorial

Quote 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.
I agree and it's true. It is based on pre standard C++ file streams. When I wrote it, only the cutting edge people really used STL and coded according to standard c++ methods. Geesh, I did not even know what a template was at that time.

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
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Dec 16th, 2005
0

Re: fstream Tutorial

Quote 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.
Have you tried deleting both the files and then running the program?

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.
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
May 1st, 2008
0

Re: fstream Tutorial

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Jul 6th, 2008
0

Re: fstream Tutorial

Can someone make a newer tutorial? None of the stuff in FireNet's tutorial will work with my compiler, I know it was probably pretty up to date when he wrote it, but Visual Studio 2008 doesn't accept the code :-(
Reputation Points: 10
Solved Threads: 0
Newbie Poster
KingCale is offline Offline
3 posts
since Jul 2008
Jul 7th, 2008
0

Re: fstream Tutorial

im using the ios::nocreate in a fstream with vc++ 2008 express but its say its not a member of std::basic_ios...
Reputation Points: 10
Solved Threads: 0
Light Poster
integer*09 is offline Offline
40 posts
since Jun 2008
Jul 7th, 2008
0

Re: fstream Tutorial

Click to Expand / Collapse  Quote originally posted by integer*09 ...
im using the ios::nocreate in a fstream with vc++ 2008 express but its say its not a member of std::basic_ios...
That flag is not available anymore, so simply don't try to use it. (The same goes for ios::noreplace )
Reputation Points: 1105
Solved Threads: 389
Posting Virtuoso
mitrmkar is offline Offline
1,714 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: C++ Style
Next Thread in C++ Forum Timeline: write aprogramme





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC