To write raw data, as opposed to formatted text, in an output stream, you must use the
write member function instead of the << operator.
Then your code is incorrect: all std::ios flags must be combined with |, you mustn't split them into two separate arguments.
std::ios::out and std::ios::trunc are implicit for std::
ofstream.
std::ios::in makes no sense for std::
ofstream.
Try this:
std::string body = avatarResponse.getBody();
std::ofstream file;
file.open("test.png", std::ios::binary);
file.write(body.c_str(), body.size());