Jump to content

[C++] How would you go about having a save system?

NeatSquidYT

Hi,

My goal is to have a save system that saves to a file for future use, but cannot be easily modified by a user.
I've seen people use structs for this, but not sure how a file output world work for that.

Link to comment
Share on other sites

Link to post
Share on other sites

If obfuscation is the intention then the structure of the file is completely irrelevant, though for the sake of clarity you might probably want to use XML - depends on your implementation details really. To obfuscate/protect the content is really the task of some form of encryption layer...

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Yes that's called a binary file. Mainly you will have a structure of how the data you will enter. For ex if you want the file to have a list of clients, you will create a structure, for ex:

struct client {int num;char name[15];char lastname[25];double account;};

and enter the data accordingly to the file.. 

 

For ex, create a temp Client called x  (Client x;)

 

The file will be an ofstream, (ofstream a ("ClientData.bin", ios::binary); )

 

Now let the user keep entering clients until he enters -1 as an account number.

cout<<"Enter the account number: ";cin>>x.num;while (x.num != -1){cin>>x.name>>x.lastname>>x.account;a.write(reinterpret_cast<char*>(&x),sizeof(client)); // THIS is how you write to the filecout<<"Enter the account number: ";cin>>x.num;}

Of course, this is just an ex, read more about binary files online and seek what you want to do with them.

Link to comment
Share on other sites

Link to post
Share on other sites

If obfuscation is the intention then the structure of the file is completely irrelevant, though for the sake of clarity you might probably want to use XML - depends on your implementation details really. To obfuscate/protect the content is really the task of some form of encryption layer...

 

I'm pretty sure he meant binary files.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm pretty sure he meant binary files.

 

Which can be manipulated quite easily. You are drawing an assumption.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

You could do some encoding and compression, maybe even encrypt it.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Or as a compromise just XOR the bytes that might be enough to dissuade the average cretin but don't count on it.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×