escrever e ler string no arquivo binário C ++

Estou tendo problemas ao escrever uma string em um arquivo binário. Este é o meu código:

ofstream outfile("myfile.txt", ofstream::binary);
std::string text = "Text";
outfile.write((char*) &text, sizeof (string));
outfile.close();

Então tento ler,

char* buffer = (char*) malloc(sizeof(string));
ifstream infile("myfile.txt", ifstream::binary);    
infile.read(buffer, sizeof (prueba));
std::string* elem = (string*) buffer;
cout << *elem;
infile.close();

Eu simplesmente não consigo fazer isso funcionar. Desculpe, estou desesperado. Obrigado!

questionAnswers(7)

yourAnswerToTheQuestion