Serialization/Unserialization of a list of strings - C++
Looks like it will work fine.
You preserve the string integrity in the file by maintaining its length as a separate entity that you can check independently. So it should work fine.

Not sure why you copy it to intermediate arrays.
Why not copy directly from input to file then from file to output?

You implement most of the other loops so precisely. But the main loop to read from the file is a bit a bit bulky and messey. With an extra class you can make it look just like the others.

std::vector&lt;std::string&gt; output;
std::ifstream in("out.txt", std::ios::in);
MyStringReader    reader;

while(in &gt;&gt; reader)
{
    output.push_back(reader);
}
in.close();


So now you just need to define the MyClassReader

struct MyStringReader
{
    std::string   data;
    operator std::string const&amp;() {return data;}  // This is used in the line
};                                                // output.push_back(reader) and converts
                                                  // the reader object into a string before
                                                  // it is pushed

std::istream&amp; operator&gt;&gt;(std::istream&amp; stream, MyStringReader&amp; value)
{
    size_t length;
    char   sep    = 'X';

    // Use the stream operators to get the size (and separator)
    // Much nicer than using tha atoi() function.
    //
    if ((stream &gt;&gt; length &gt;&gt; sep) &amp;&amp; (sep == '|'))
    {
        // Resize the string to the correct size and put the word into it.
        value.data.resize(length);
        stream.read(&amp;value.data[0], length);
    }
    return stream;
}