如何在输出运算符中测试std::showbase或std::noshowbase
How to test for std::showbase or std::noshowbase in output operator?
我有一个大的整数类,我正试图使它尊重std::showbase
和std::noshowbase
。这里,"荣誉"意味着控制Integer类中定义的后缀的使用(而不是C++标准行为):
std::ostream& operator<<(std::ostream& out, const Integer &a)
{
...
if(out.flags() & std::noshowbase)
return out;
return out << suffix;
}
然而,它会导致一个错误:
$ make static
c++ -DDEBUG -g3 -O1 -fPIC -Wno-tautological-compare -Wno-unused-value -DCRYPTOPP_DISABLE_ASM -pipe -c integer.cpp
integer.cpp:3487:17: error: invalid operands to binary expression ('int' and
'std::ios_base &(*)(std::ios_base &)')
if(out.flags() & std::noshowbase)
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
/usr/include/c++/4.2.1/bits/ios_base.h:79:3: note: candidate function not
viable: no known conversion from 'std::ios_base &(std::ios_base &)' to
'std::_Ios_Fmtflags' for 2nd argument
operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
^
1 error generated.
我也尝试过有类似错误的std::ios::noshowbase
和std::ios_base::noshowbase
。
如何测试showbase
和noshowbase
?
noshowbase
是一个函数,而不是位掩码类型的积分。也没有ios_base::noshowbase
。但有ios_base::showbase
。也许你想要:
if (out.flags() & std::ios_base::showbase) {
return out << suffix;
}
return out;
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何从 std::atomic 中提取指针 T<T>?
- 如何在输出运算符中测试std::showbase或std::noshowbase
- std::showbase和std::showpos互斥吗?
- 解决std::showbase不加零前缀的问题