Sign in to follow this  

Saving Variables C++/Dev-Net

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

There are a few ways, one is serialize your object then save it to a flatfile, it's probably the easiest way. The most effecient way would be to output it to a Database, create a table for your array. Not only is it effecient but proper database management allows you to do some pretty cool things with your data such as sort it, update it, cross reference it ect. Check out SQL, MS access, oracle ect for database types.

Share this post


Link to post
Share on other sites
I'm probably going to get slammed here for suggesting C-style stuff but...


int a[10]={ 1,2,3,4 etc };

FILE *fp=fopen("file","wb");
fwrite(a,sizeof(int),10,fp); // to write

FILE *fp=fopen("file","rb");
fread(a,sizeof(int),10,fp); // to read



is probably the easiest way to read/write an array.

Share this post


Link to post
Share on other sites
If you want to know the c++ way then this site here is pretty good:

http://www.cplusplus.com/doc/tutorial/files.html

It covers reading binary toward the end of the article. And for quick reference the code to read and write in c++ is:
char memblock[20];

// reading in
fstream file = ("example.dat", ios::in | ios::binary);
file.read(memblock, 20);

// writing out
fstream file = ("example.dat", ios::out | ios::binary);
file.write(memblock, 20);


Just to show that the C way isn't really any simpler.

Share this post


Link to post
Share on other sites

This topic is 4255 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.

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

Sign in to follow this