samedi 23 février 2019

How to read a string with '\0' at the end from binary file

I am trying to read a string from binary file (I don't know its' size, but it is guaranteed that this is c-string). I have tried to do smth like this:

s_m._name = "";
std::getline(os, s_m._name, '\0');

and this:

string result;
char ch;
while (os.get(ch) != '\0') {
  result += ch;
 }

Aucun commentaire:

Enregistrer un commentaire