out_of_range 类

类用作。所有引发的异常的基类。报告超出其有效的参数。

class out_of_range : public logic_error {
public:
    explicit out_of_range(const string& message);
    explicit out_of_range(const char *message);
};

备注

exception 类 返回的值为 message.数据副本。

示例

// out_of_range.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

using namespace std;

int main() {
// out_of_range
   try {
      string str( "Micro" );
      string rstr( "soft" );
      str.append( rstr, 5, 3 );
      cout << str << endl;
   }
   catch ( exception &e ) {
      cerr << "Caught: " << e.what( ) << endl;
   };
}

Output

Caught: invalid string position

要求

页眉:<stdexcept>

命名空间: std

请参见

参考

logic_error 类

C++ 标准库中的线程安全