Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c+中的函数+;为什么我的编译器没有';无法识别错误() C++中使用Error()函数获取错误。p>_C++ - Fatal编程技术网

c+中的函数+;为什么我的编译器没有';无法识别错误() C++中使用Error()函数获取错误。p>

c+中的函数+;为什么我的编译器没有';无法识别错误() C++中使用Error()函数获取错误。p>,c++,C++,我的问题是,当我想在代码中包含error()函数时,会出现编译错误。 编译器似乎无法识别此函数 int some_function(){ double input{0}; cin>>input; if(!cin){ error("couldn't read double in 'some_function()'"); return -1; } 我希望在“输入字符串”时,“不能读取双函数

我的问题是,当我想在代码中包含error()函数时,会出现编译错误。
编译器似乎无法识别此函数

int some_function(){
        double input{0};
        cin>>input;
        if(!cin){
        error("couldn't read double in 'some_function()'");

        return -1;
        }

我希望在“输入字符串”时,“不能读取双函数”(),“

< p> > C++标准库中没有<代码>错误< /代码>函数。编译器无法“识别”此函数,因为它不存在

你认为为什么会有这样一个功能

如果要在C++中打印错误消息,通常的方法是使用<代码> Curr < /Cord>流:

std::cerr << "couldn't read double in 'some_function()'\n";

<代码> STD::CERP R C++没有标准<代码>错误< /代码>函数。什么是<代码>错误< /代码>函数?您想要使用什么?编译错误?请提供一个可能的错误指令?我是C++中的一个新的LITTEL位,我有许多程序员使用错误函数的ReMARCK,我认为它是一个标准函数。我试过cerr,它对tazsk做得很好,我感谢melpomene和其他人提出的关于编译时错误的问题。当编译器试图将程序转换为对象文件时,会出现这些错误。经过一些研究,我发现error()函数必须由程序员实现,并且必须包含在其主体中{throw runtime_error(字符串的名称…;}),它是一个具有字符串类型参数的void函数,并且trow运行时错误不是编译时错误,谢谢!