Jump to content
  • Advertisement

Archived

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

TheNerd Tk421

Saving and opening files in a game...

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

Advertisement
I think you mean binary files so you should look up these functions.. fread() fwrite()...to make things easier go here there''s the definitions to the functions you want

Share this post


Link to post
Share on other sites
Or you could use some c++ objects for in/output.

int the header

there are: std::ifstream and std::ofstream.

//For output, just create an ofstream object.
std::ofstream MyFile;
//then open the file
MyFile.open("MySuperCoolFile.txt");
//then write things to it:
MyFile << "I am sooo coool\n";
//then close the file
MyFile.close();


So, all done, now just look in "MySuperCoolFile.txt" on your disk and see if anything happend! :-)

----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. The who understand binary and those who don''t"

Share this post


Link to post
Share on other sites
When I save stuff I usually declare a struct with variables that hold the data I want to save. Then I just copy the entire struct (binary mode) to a file using the write() and read() method from std::ofstream and std::ifstream.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!