c++ Reading string from binary file using fstream
问题 I am trying to read a string from a binary file but cant seem to get it to work. I am a pretty new to c++. Can anybody help please? Thanks. string Name = "Shaun"; unsigned short int StringLength = 0; int main() { StringLength = Name.size(); ofstream oFile("File.txt", ios::binary|ios::out); oFile.write((char*)&StringLength, sizeof(unsigned short int)); oFile.write(Name.c_str(), StringLength); oFile.close(); StringLength = 0; Name = "NoName"; ifstream iFile("File.txt", ios::binary|ios::in); if(