我知道那basefield
是.dec/oct/hex
setf
basefield
#include <iostream>
using namespace std;
int main()
{
typedef ios_base::fmtflags fmt;
fmt a, b, c = cout.basefield;
cout << "basefield: " << hex << c << endl;
cout << dec;
a = cout.flags();
b = a & c;
cout << "\ndec flags:\n";
cout << " a: " << hex << a << endl;
cout << " b: " << hex << b << endl;
cout << oct;
a = cout.flags();
b = a & c;
cout << "\noct flags:\n";
cout << " a: " << hex << a << endl;
cout << " b: " << hex << b << endl;
cout << hex;
a = cout.flags();
b = a & c;
cout << "\nhex flags:\n";
cout << " a: " << hex << a << endl;
cout << " b: " << hex << b << endl;
cout.setf(cout.flags() & ~cout.basefield);
a = cout.flags();
b = a & c;
cout << "\nunset basefiled:\n";
cout << " a: " << hex << a << endl;
cout << " b: " << hex << b << endl;
}
g++ 4.8.1 结果是:
basefield: 4a
dec flags:
a: 1002
b: 2
oct flags:
a: 1040
b: 40
hex flags:
a: 1008
b: 8
unset basefiled:
a: 1008
b: 8
当取消设置所有基础标志值设置为与十六进制标志相同时,我运行代码 Visual C++ 2008 和 Intel C++ XE,结果为:
basefield: e00
dec flags:
a: 201
b: 200
oct flags:
a: 401
b: 400
hex flags:
a: 801
b: 800
unset basefiled:
a: 801
b: 800
十六进制标志似乎与所有未设置的基数完全相同。
我想要的只是将标志设置为一个值,而不是dec\oct\hex
这样当我实现自己的操纵器时,我可以检测到我的格式或流格式正在使用哪种格式。
谢谢。