有一个题目是bitset 提供了成员函数,to_ulong,如果bitset提供了超出unsigned long的位数长度时,抛出一个over_flow的异常,编写这样的程序.我做的结果如下:
#include <iostream>
#include <vector>
#include <stdexcept>
#include <bitset>
int main()
{
unsigned long long _Initiliztion_Ibitset;
std::bitset<32> _Varible_Bitset(_Initiliztion_Ibitset);
try {
_Varible_Bitset.to_ullong();
throwstd::overflow_error("The varible rang was more than parameter tha system default");
}
catch (std::overflow_error Error)
{
std::cout<<Error.what();
system("pause");
}
return0;
}
这个 运行起来 抛出了异常 可是下面的 怎么还抛出异常:
#include <iostream>
#include <vector>
#include <stdexcept>
#include <bitset>
int main()
{
long _Initiliztion_Ibitset;//这里的long型的rang明显要小于,unsigned long 怎么还抛出异常
std::bitset<32> _Varible_Bitset(_Initiliztion_Ibitset);
try {
_Varible_Bitset.to_ullong();
throwstd::overflow_error("The varible rang was more than parameter tha system default");
}
catch (std::overflow_error Error)
{
std::cout<<Error.what();
system("pause");
}
return0;
}
子衿沉夜
九州编程
相关分类