C ++中的函数为什么我的编译器无法识别错误()

function in c++ why my compiler didn't recognize the error()

本文关键字:识别 错误 编译器 我的 函数 为什么      更新时间:2023-10-16

在 C++ 中使用 error(( 函数时出错。

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

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

当我输入例如字符串时,我希望消息"无法在'some_function(('中读取双倍"。

C++标准库中没有error函数。编译器无法"识别"此函数,因为它不存在。

为什么你认为应该有这样的功能?

如果要在C++中打印错误消息,通常的方法是使用cerr流:

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