October 20th, 2013, 01:51 PM
Re: Save/load functions not working
How is a general method going to know what your object consists of? You still have to write the code to output the contents to a file, and write the code to read the file. There are no shortcuts.
Originally Posted by KruSuPhy
The question really should be how you do this. In C++, you could overload the streaming operators (operator << for output and operator >> for input) for the class.
One thing I don't recommend is that "LoadGame()" pseudo-code you have. You shouldn't mix error handling with file reading logic in the same function. What if you want to read the file, and if it doesn't exist, output an error to a log file, or read from an alternate file, or any number of other things? The LoadGame() should just return an error or throw an exception if the file doesn't exist and not do anything else. Then the caller decides what to do instead of LoadGame() controlling what is done.
However did you do as D_Drmmr stated?
When you try to learn something new in C++, it's best to start with a small example to get familiar with the topic before using those techniques in an existing program. Just write a simple program that writes an int, a double and a string to a file and reads it back.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!