I want to encode this string however, are there any other ways to encode an std::string to make it non-decipherable by humans
By humans. Which humans?
Personally I classify them as:
- "My Stupid Brother"
- "My Nosy but Smart Mum"
- "A competing Company"
- "The government".
Encryption to beat people:
- Brother: (add 'N' to each character) (subtract 'N' to decode)
- Mother: (XOR a key)
- Company: Noting short of a real encryption package (eg SHA-512)
- Government: Yea right.
If they want to get something from me I have no chance.
So I hire a professional company to handle it.
For now, I decided that I would serialize AddressBook would be to write an encoded version of each contact on a separate line in the file which would be opened in binary mode.
Binary/Text mode there is no real difference. Binary mode just means that '\n' is not converted to/from the End of Line Sequence.
It'll basically be a string which I'll parse later to get the values, somewhere along these lines: "John~Doe~42"
Sure, but I would use ' ' (space) as the separator (as the stream library already uses as the default seporator). This will make the code much easier to write. As previously noted strings need to be encoded with their length (unless you have fixed length strings).
because if my Person class gets many new member variables, this string can get quite long.
If you are planning to encode more information latter then I would also add a version field. Thus you read the version number first, this tells you what other fields to expect next.
I was hoping that it could be encoded as hex representation
This does not make sense.
Everything is just a number.
if not compact?
Sure you can compress the data.
Look up compression algorithms.