fstream Tutorial

Reply

Join Date: Jun 2005
Posts: 1
Reputation: lntrovertido is an unknown quantity at this point 
Solved Threads: 0
lntrovertido lntrovertido is offline Offline
Newbie Poster

Re: fstream Tutorial

 
0
  #41
Jun 1st, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,141
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1434
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: fstream Tutorial

 
0
  #42
Aug 16th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #43
Dec 16th, 2005
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
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #44
Dec 16th, 2005
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.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,141
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1434
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: fstream Tutorial

 
0
  #45
May 1st, 2008
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 3
Reputation: KingCale is an unknown quantity at this point 
Solved Threads: 0
KingCale KingCale is offline Offline
Newbie Poster

Re: fstream Tutorial

 
0
  #46
Jul 6th, 2008
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 :-(
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 35
Reputation: integer*09 is an unknown quantity at this point 
Solved Threads: 0
integer*09 integer*09 is offline Offline
Light Poster

Re: fstream Tutorial

 
0
  #47
Jul 7th, 2008
im using the ios::nocreate in a fstream with vc++ 2008 express but its say its not a member of std::basic_ios...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: fstream Tutorial

 
0
  #48
Jul 7th, 2008
Originally Posted by integer*09 View Post
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 )
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC