比较c++中的int和bitset
Compare int and bitset in c++
如何将bitset与整数进行比较?或者更一般地使用整数运算符:像这样:
#include <iostream>
#include <iomanip>
#include <bitset>
using namespace std;
int main()
{
bitset<4> _b1 = 3 ;
if(_b1>=2 )
cout<<_b1;
system("pause");
return 0;
}
使用std::bitset<N>::to_ulong()
:
if(_b1.to_ulong() >= 2)
bitset的to_ulong
方法返回bitset
的值为unsigned long
您可以使用to_ulong
来获取bitset的unsigned int值:
_b1.to_ulong()
这里是ref.在你的例子中,它会:
if(_b1.to_ulong()>=2 )
cout<<_b1;
还应该避免system("pause")
您可以使用to_ulong(),并与long进行比较,或者可能将ulong转换为int。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 'short int'持有的值溢出,但"自动"不会溢出?
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 调用'begin(int [n])'没有匹配函数
- 没有显式声明的int[]中的foreach
- 在c++中访问int到类对象的映射时出错
- 为什么我无法更改"set<set>"循环中的值<int>
- 如何以滑动窗口方式从 std::bitset 读取位并将它们转换为 int?
- 初始化一对(bitset,int)的向量
- 使用无符号 int 而不是 std::vector<bool> 或 std::bitset 是推荐的做法吗?
- 将多个int类型的值赋给bitset
- 比较c++中的int和bitset