ビットセットを整数と比較するにはどうすればよいですか? または、より一般的には整数演算子で動作します: 次のようなもの:
#include <iostream>
#include <iomanip>
#include <bitset>
using namespace std;
int main()
{
bitset<4> _b1 = 3 ;
if(_b1>=2 )
cout<<_b1;
system("pause");
return 0;
}
if(_b1.to_ulong() >= 2)
a の値をas としてto_ulong
返す bitsetのメソッドがあります。bitset
unsigned long
to_ulong
ビットセットの unsigned int 値を取得するために使用できます。
_b1.to_ulong()
ここに参照があります。あなたの場合、次のようになります。
if(_b1.to_ulong()>=2 )
cout<<_b1;
また、 system("pause")を避ける必要があります。
to_ulong() を使用して long と比較したり、ulong を int に変換したりすることができます。