|
Post by fwiss on Mar 9, 2011 20:07:14 GMT -5
I have a serious problem with saving and loading (Standard Library file io) I use short ints but I use code like this:
void SAVE(signed short a[7],int b[4])//Requires character stats and inventory. { ofstream sav; sav.open ("SAVE", ios::trunc ); sav <<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<" "<<a[6] <<" "<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]; sav.close(); }
How would I go about loading these into short ints?
|
|
|
Post by aphoticgenesis on Mar 9, 2011 23:26:31 GMT -5
I'm not trying to avoid the answer to your question but I would recommend you use some kind encoding, like binary encoding, with a data structure, just so that way the saved data can only be read through the custom file structure header you write. If you need help with that just post back, I'll write an example with comments that give you the answer to your question and the solution to my proposition. 
|
|
|
Post by fwiss on Mar 10, 2011 6:53:40 GMT -5
I understand the concept of binary. Buuuuuuuut I'm not good with it in C++... Also, in my code, my main problem is places. These are all ints, but say in the editor it returns... 1 20 20 5 5 5 2 1 0 0 1 0. Does C++ read it as such, or does it read it as a hex editor does, 31 32 30 20 32 30 20 ... ETC. The hex editor reads 20 as a space, which is supposed to be my separator (separates the values) However, since my values change, they may once contain 20 in them.
|
|
|
Post by fwiss on Mar 10, 2011 7:06:58 GMT -5
In other words, I think it would be practical to try and make the numbers always have the same number of digits, ex. 000001 000020 000020 000005 000005 000005 etc., so that they can all be read normally no matter how many digits it has. Ex. if 000005 changes to 21, I need it to be 000021, not 0000021. Same number of digits in every int in other words. Also, does c++ read this as char (string) or int?
|
|
|
Post by fwiss on Mar 10, 2011 22:21:43 GMT -5
Great, I can't even figure out how to read from file....
|
|
|
Post by DJLinux on Mar 11, 2011 1:41:17 GMT -5
|
|
|
Post by fwiss on Mar 11, 2011 17:55:53 GMT -5
Thank you! I finally sorted out the bugs and got it working.
|
|