Encrypting/ decrypting vector<string>
<p>I've been working on a personal serializing process, but I'm stuck at getting back the decrypted vector after saving/loading. It saves and loads the data just fine, but the vector inventory loses it's definition in the transition, so I have to remake it, which removes the ability to use it later in the program. The below snippet of code shows how I encrypt/ decrypt.</p>

<pre><code>struct bin{
    map&lt;string, int&gt;::iterator it;
    int modify_string;
    vector&lt;string&gt; uncrypt_vec;
    map&lt;string, int&gt; encryption;
    void set_up_code(){
        string alphabet[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        int letter_num=1;
        for(int i = 0; i &lt; 27; ++i){
            string letter = alphabet[i]; //Assign each letter to a number
            encryption.insert(pair&lt;string,int&gt;(letter,letter_num));
            letter_num++;
        }
        encryption.insert(pair&lt;string,int&gt;(" ", -1));
    }
    int encrypt_vector(vector&lt;string&gt;&amp; crypt){
        stringstream ssv;
        for(unsigned int i = 0; i &lt; crypt.size(); ++i){
            string word = crypt[i]; //Grab each string
            int mod_word[word.size()];
            for(unsigned int x = 0; x &lt; word.size(); ++x){
                stringstream ssl;
                string letter;
                char let = word[x]; //Convert each letter of the string into an integer
                ssl &lt;&lt; let;
                ssl &gt;&gt; letter;
                int num = encryption[letter];
                mod_word[x] = num;
            }
            mod_word[word.size()] = 0; //Include a zero for each word
            copy(mod_word, mod_word+word.size()+1, ostream_iterator&lt;int&gt;(ssv));
        }
        ssv &gt;&gt; modify_string; //Put into int modify_string and return
        return modify_string;
    }
    vector&lt;string&gt; decrypt_vector(int&amp; uncrypt){
        string num;
        stringstream ssn;
        ssn &lt;&lt; uncrypt; //Store the numbers in a string
        ssn &gt;&gt; num;
        string mod_word;
        string word;
        for(unsigned int i=0;i&lt;num.size();++i){
            int number;
            char check_num = num[i];
            stringstream ssctn;
            ssctn &lt;&lt; check_num; //Kinda stupid way of doing it
            ssctn &gt;&gt; number; //Pulls int from num[i], then checks it against 0
            if(number==0){ //If break point
                uncrypt_vec.push_back(mod_word); //Push back the word
                mod_word.clear();
            }
            int letter;
            stringstream sscn;
            char let = num[i];
            sscn &lt;&lt; let; //Pull each letter from uncrypt, change back to letter based on encryption
            sscn &gt;&gt; letter;
            for(it = encryption.begin(); it != encryption.end(); ++it){
                if(it-&gt;second == letter){
                    mod_word.append(it-&gt;first);
                    break;
                }
            }
        }
        cout &lt;&lt; "Done" &lt;&lt; endl;
        return uncrypt_vec;
    }
}binary;

struct player{
    vector&lt;string&gt; inventory;
    int inventory_en; //en for encrypted
    void save(){
        inventory_en = binary.encrypt_vector(inventory);
    }

    void load(){
        vector&lt;string&gt; inventory; //Must recreate, type is lost otherwise, crashes
        inventory = binary.decrypt_vector(inventory_en);
        vector&lt;string&gt;::iterator i;
        for(i=inventory.begin();i!=inventory.end();++i){
            cout &lt;&lt; *i &lt;&lt; endl; //Prints correctly here
        }
    }
}character;

int main(){
    character.inventory.push_back("abc");
    character.inventory.push_back("edf");
    binary.set_up_code();
    character.save();
    character.load();
}
</code></pre>

<p>When I try to print out character.inventory later, it crashes. And if I don't define character.inventory as a string in the character.load() function, it also crashes. So how can I get character.inventory defined as a vector that I can call (from the struct) later in the program?</p>

<p>I write data to files using <code>output_file.write((char*)&amp;structObj, sizeof(structObj));</code> and read out the same way (hence the need to encrypt/ decrypt, can't save strings this way).</p>

<p>And please don't direct me to a library to do it for me.</p>
