int a=60;
cout<<setiosflags(ios::hex|ios::showbase|ios::uppercase);
cout<<a<<endl;
上面的代码不起作用,但如果我使用
cout<<hex
进而
cout<<setiosflags(ios::showbase|ios::uppercase)
然后它正在工作
为什么?以及我怎么知道哪一个可以在 setiosflags() 中使用?
最佳答案
您需要调用 resetiosflags
在您调用 setiosflags
之前.原因是 setiosflags(ios::hex|ios::showbase|ios::uppercase)
只需将这些标志附加到流中,就像调用 setf
这会在流中给出冲突的标志。使用
std::cout << std::resetiosflags(std::ios_base::dec)
<< std::setiosflags(std::ios::hex|std::ios::showbase|std::ios::uppercase)
<< a << endl;
将使其显示
a
正确。
关于c++ - 在 setiosflags 函数中使用十六进制标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62069504/