Data Structure File I/O

Started by
16 comments, last by elis-cool 22 years ago
quote:Original post by elis-cool
Well I dont really want to write in text mode (possible sensitive info)...

But if I have to I could encrypt it... and have something like so saved to a file:
...


I don''t see how a binary file is any more secure that a text file.

[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
Advertisement
Anything wrong with this??
struct Data{   string str;   int value;   double anotherValue;   unsigned char byteCode;};struct Node{   Data data;   Node* next;   Node()   {      next = NULL;   }};// Node* pTail = tail of listNode* pTemp;pTemp = pHead;while(pTemp != NULL){   file.write((char*)&pTemp->data, sizeof(Data));   pTemp = pTemp->next;}file.close(); 


Might not compile right out of the box, consider it to be "pseudocode"..



pTemp = pTail
Yes, there''s something very wrong with that, which is to do with what Fruny has already said. Those strings will not be saved properly. You can''t use fwrite on strings.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions ]
I didnt think you could as I had problems with it a few weeks ago...
Well a binary is a bit more secure as some random Joe bob cant just open the file in notepad and read everything, it would at least take someone trying to do it, to do it.
What if the Data class held a char name[] and put the string into that, that should work...
Well since this is a Database prog, how does GDnet store its info Dave?

CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
Um, I have some struct''s with strings of varying length and they always get written and read just fine.

About saving the nodes, read and write the entire node and just be sure to give the pointer a new value(malloc or new) before using it(inserting it into the list).
quote:Original post by RolandofGilead
Um, I have some struct''s with strings of varying length and they always get written and read just fine.

Then it''s probably a POD struct.
quote:
About saving the nodes, read and write the entire node and just be sure to give the pointer a new value(malloc or new) before using it(inserting it into the list).

This technique is only adequate for POD types. It breaks as soon as you go beyond that.


[C++ FAQ Lite | ACCU | Boost | Python]
Dave???

CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]

This topic is closed to new replies.

Advertisement