1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <iomanip> 10 11 // T3 setbase(int base); 12 13 #include <iomanip> 14 #include <istream> 15 #include <ostream> 16 #include <cassert> 17 18 template <class CharT> 19 struct testbuf 20 : public std::basic_streambuf<CharT> 21 { 22 testbuf() {} 23 }; 24 25 int main() 26 { 27 { 28 testbuf<char> sb; 29 std::istream is(&sb); 30 is >> std::setbase(8); 31 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); 32 is >> std::setbase(10); 33 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); 34 is >> std::setbase(16); 35 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); 36 is >> std::setbase(15); 37 assert((is.flags() & std::ios_base::basefield) == 0); 38 } 39 { 40 testbuf<char> sb; 41 std::ostream os(&sb); 42 os << std::setbase(8); 43 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); 44 os << std::setbase(10); 45 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); 46 os << std::setbase(16); 47 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); 48 os << std::setbase(15); 49 assert((os.flags() & std::ios_base::basefield) == 0); 50 } 51 { 52 testbuf<wchar_t> sb; 53 std::wistream is(&sb); 54 is >> std::setbase(8); 55 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct); 56 is >> std::setbase(10); 57 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec); 58 is >> std::setbase(16); 59 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex); 60 is >> std::setbase(15); 61 assert((is.flags() & std::ios_base::basefield) == 0); 62 } 63 { 64 testbuf<wchar_t> sb; 65 std::wostream os(&sb); 66 os << std::setbase(8); 67 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct); 68 os << std::setbase(10); 69 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec); 70 os << std::setbase(16); 71 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex); 72 os << std::setbase(15); 73 assert((os.flags() & std::ios_base::basefield) == 0); 74 } 75 } 76