<stdexcept> http://www.cplusplus.com/reference/stdexcept/

本文详细介绍了C++标准库中&lt;stdexcept&gt;头文件内的各类异常。包括运行时错误如runtime_error、range_error等,以及逻辑错误如logic_error、domain_error等。通过对这些异常的理解,可以帮助开发者更好地处理程序中可能出现的问题。
<stdexcept>头文件里面几个类的作用
exception                                 最常见的问题
runtime_error                        运行时错误:仅在运行时才能检测到得错误
range_error                           运行时错误:生成的结果超出了有意义的值域范围
overflow_error                       运行时错误:计算上溢
underflow_error                    运行时错误 :计算下溢
logic_error                            逻辑错误:可在运行前检测到得问题
domain_error                        逻辑错误:参数的结果值不存在
invalid_argument                  逻辑错误:不合适的参数
length_error                          逻辑错误:试图生成 一个超出改类型最大长度的对象
out_of_range                        逻辑错误:使用一个超出有效范围的值

编译错误. main.cpp: In member function 'void Fraction::simplify()': main.cpp:11:49: error: 'gcd' was not declared in this scope int gcd_val = gcd(numerator, denominator); ^ main.cpp: In member function 'Fraction Fraction::operator/(const Fraction&) const': main.cpp:45:54: error: 'invalid_argument' was not declared in this scope throw invalid_argument("Division by zero"); ^ main.cpp: In function 'int main()': main.cpp:77:9: error: cannot bind 'std::istream {aka std::basic_istream<char>}' lvalue to 'std::basic_istream<char>&&' cin >> f1 >> f2; //让用户输入两个分数,格式:分子/分母,如 2/6 24/14 ^ In file included from /usr/include/c++/4.8.2/iostream:40:0, from main.cpp:1: /usr/include/c++/4.8.2/istream:872:5: error: initializing argument 1 of 'std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = Fraction]' operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) ^ main.cpp:85:31: error: 'setiosflags' was not declared in this scope cout <<setiosflags(ios::fixed)<<setprecision(2) << 0.8 + f2 << endl; //0.8+f2结果为浮点类型 ^ main.cpp:85:48: error: 'setprecision' was not declared in this scope cout <<setiosflags(ios::fixed)<<setprecision(2) << 0.8 + f2 << endl; //0.8+f2结果为浮点类型 ^ main.cpp:85:57: error: no match for 'operator+' (operand types are 'double' and 'Fraction') cout <<setiosflags(ios::fixed)<<setprecision(2) << 0.8 + f2 << endl; //0.8+f2结果为浮点类型 ^ main.cpp:85:57: note: candidates are: In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0, from /usr/include/c++/4.8.2/bits/char_traits.h:39, from /usr/include/c++/4.8.2/ios:40, from /usr/include/c++/4.8.2/ostream:38, from /usr/include/c++/4.8.2/iostream:39, from main.cpp:1: /usr/include/c++/4.8.2/bits/stl_iterator.h:333:5: note: template<class _Iterator> std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&) operator+(typename reverse_iterator<_Iterator>::difference_type __n, ^ /usr/include/c++/4.8.2/bits/stl_iterator.h:333:5: note: template argument deduction/substitution failed: main.cpp:85:59: note: 'Fraction' is not derived from 'const std::reverse_iterator<_Iterator>' cout <<setiosflags(ios::fixed)<<setprecision(2) << 0.8 + f2 << endl; //0.8+f2结果为浮点类型 ^ In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0, from /usr/include/c++/4.8.2/bits/char_traits.h:39, from /usr/include/c++/4.8 为什么错了 怎么改
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值