From 904224fbfc9faff82256751d3147fbc50ec5e9d7 Mon Sep 17 00:00:00 2001 From: Riccardo Corsi Date: Wed, 9 Sep 2020 15:42:02 +0200 Subject: [PATCH] Stream << operator: restore original flags after streaming the uuid --- include/uuid.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/uuid.h b/include/uuid.h index 34f59e5..93de802 100644 --- a/include/uuid.h +++ b/include/uuid.h @@ -541,7 +541,11 @@ namespace uuids template std::basic_ostream & operator<<(std::basic_ostream &s, uuid const & id) { - return s << std::hex << std::setfill(static_cast('0')) + // save current flags + std::ios_base::fmtflags f(s.flags()); + + // manipulate stream as needed + s << std::hex << std::setfill(static_cast('0')) << std::setw(2) << (int)id.data[0] << std::setw(2) << (int)id.data[1] << std::setw(2) << (int)id.data[2] @@ -562,6 +566,11 @@ namespace uuids << std::setw(2) << (int)id.data[13] << std::setw(2) << (int)id.data[14] << std::setw(2) << (int)id.data[15]; + + // restore original flags + s.flags(f); + + return s; } template