'error ()' c++ 中的函数不适用于 Visual Studio 2015
'error ()' Function in c++ is not working for Visual Studio 2015
我是第一次接触编程概念和使用像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函数,并让它做您想做的事情。
相关文章:
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- 为什么 std::erase(std::erase_if) 不是适用于<algorithm>任何容器的模板?
- 为什么这适用于 G++ 而不是 CLANG?
- 为什么不区分大小写适用于 std::unordered_set的 std::hash 函数?
- 声明适用于 auto,但不能显式声明类型?
- 什么是通用运行时组件 #ifdef 适用于Windows(UWP)而不是iOS
- Windows 上的 Cmake 不添加共享库路径(适用于 linux)
- Typedef适用于结构,但不适用于枚举,仅适用于C++
- 为什么函数模板不理解 NULL,但适用于 nullptr
- 链接器读取库,但在其中找不到符号?未解析的外部符号,但仅适用于 Win32 而不是 x64
- Netbeans 8.1(适用于 C/C++)找不到我的编译器(gcc-6.0.0 开发版本)
- random_shuffle() 适用于 Windows,但不能在 Linux 上编译
- C++指针到方法模板推导在面向 x86 时不编译,但适用于 x64
- 不在异常中嵌入std::字符串的规则是否仍然适用于move构造函数
- 移动文件夹Windows c++:适用于Vista及以上版本,不包括XP
- 适用于Android的Qt找不到任何兼容的设备答案找到但不知道如何
- 在Windows 7上不起作用,但它适用于Windows 8 dll。
- 可变参数模板转换为 std::function<R(ARGS...)>适用于 GCC 而不是 MSVC2013,为什么?
- C++11 cmath 函数不在 std 命名空间中,适用于 android NDK w/gcc-4.8 或 clang