That is because you have not added a null character to tell
cout
where the end of the buffer is. Try:
int filesize = myfile.tellg();
char *content = new char[filesize + 1]; myfile.seekg(0, ios::beg);
myfile.read(content, filesize);
content[filesize] = '\0';
Note this code is over simplified.