c++ - Best way to parse a stringstream -
i have std::stringstream contains data given file. file contains text binary data.
in beginning there string name, way:
std::string name; std::getline(stream, name, '\0'); later on, need retrieve contentlength. part i'm failing:
int32_t contentlength; stream >> contentlength; i learned won't work, since stream >> operator try convert instead of casting 4 bytes literal value of length.
i have seen low level (c) implementation of how that. guys advise me of more reliable way of doing it.
you can use read function read binary data.
stream.read((char*)&contentlength, sizeof(contentlength)); you need careful if share file between computers different endianness, in case bytes might need reversed.
Comments
Post a Comment