Im having problems writing string into a binary file. This is my code:
ofstream outfile(\"myfile.txt\", ofstream::binary);
std::string text = \"Text\";
outfi
the line
outfile.write((char*) &text, sizeof (string));
is not correct
sizeof(string) doesn't return the length of the string, it returns the sizeof the string type in bytes.
also do not cast text to char* using a C cast, you can get hold of the char* by using the appropriate member function text.c_str()
you can simply write
outfile << text;
instead.