//为了方便,要包含的文件会不同,但我没有删
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <cstring> //和C语言的string.h其实是一个版本
#include <exception>
using std::bitset;
using std::vector;
using std::cin;
using std::endl;
using std::cout;
using std::string;
using std::overflow_error;
//---------------------------------------------------------------------------
int main()
{
bitset<32> bitvec32;
bitset<38> bitvec38;
bitvec32.set();
bitvec38.set();
unsigned long ul=0;
if(bitvec38.size()>sizeof(ul))
throw overflow_error("bitvec太大,无法转换为unsigned long");
ul=bitvec38.to_ulong();
cout<<"ul="<<ul<<endl;
return 0;
}
/*
189页习题6.23一个产生overflow_error异常的程序
*/