From 03b770fdf267a53b407bb05ee2fb6b56564450eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=2E=20Bravo?= Date: Fri, 28 Oct 2016 15:27:03 -0500 Subject: [PATCH] Save the flags of the stream Changing the stream to `std::hex` mode should only affect the current character; otherwise printing some msgpack with a list like this: `[123, "string\\u0003", 123]` (123 decimal) ends up printing `[123, "string\\u0003", 7b]`, as `std::hex` is sticky. --- include/msgpack/v1/object.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/msgpack/v1/object.hpp b/include/msgpack/v1/object.hpp index 7e6dac14..f098a874 100644 --- a/include/msgpack/v1/object.hpp +++ b/include/msgpack/v1/object.hpp @@ -802,7 +802,9 @@ inline std::ostream& operator<< (std::ostream& s, const msgpack::object& o) default: { unsigned int code = static_cast(c); if (code < 0x20 || code == 0x7f) { + std::ios::fmtflags flags(s.flags()); s << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (code & 0xff); + s.flags(flags); } else { s << c;