'error ()' c++ 中的函数不适用于 Visual Studio 2015

'error ()' Function in c++ is not working for Visual Studio 2015

本文关键字:不适用 适用于 Studio 2015 函数 Visual error c++      更新时间:2023-10-16

我是第一次接触编程概念和使用像Visual Studio这样的软件。所以现在我正在学习c++语言。当我试图处理C++中的error ()函数时,它给我一个错误消息说"ConsoleApplication3.exe中0x76DE3E28处未处理异常:Microsoft c++异常:std::runtime_error在内存位置0x0116F8CC."。下面是我的代码示例:

#include "stdafx.h"
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <algorithm>
#include "std_lib_facilities.h"
using namespace std;
int area(int w , int l)
{
if (w <= 0 || l <= 0) error("There's something went wrong!");
    return w / l;
}
int main()
{
    int x = 3;
    int y = 0;
    cout << area(x, y) << endl;
    keep_window_open();
}

我检查了很多次,没有发现代码有任何问题。我在代码上做错了什么吗?请帮帮我,伙计们。非常感谢!!

这是Bjarne Stroustrup的头文件之一。如果您查看异常发生的位置,您将看到正在抛出异常。你所看到的是意料之中的。你不应该对你刚得到的代码做任何假设。创建您自己的error函数,并让它做您想做的事情。

相关文章: