Here is an example struct:
struct Person
{
std::string Name;
int Age;
};
And Here is how i write it to an fstream:
Person p;
p.Name = "Mike";
p.Age = 21;
stream.write((char*)&p, sizeof(p));
As you can see above I write my Person variable to an fstream using write()
function. Person's name is written to the stream as "Mike" but when i use it with a const char*
it just writes the address to the string. What i do not understand is this: How does fstream write std::string's value but not the pointer to the string itself?