首页 > 解决方案 > function in c++ why my compiler didn't recognize the error()

问题描述

getting error using error() function in c++.

my problem is when i wanted to include the error() function to my code i get compilation errors.
it seems that the compiler does not recognize this function.

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

        return -1;
        }

i expected the message "couldn't read double in 'some_function()'" when i input for example a string.

标签: c++

解决方案


There is no error function in the C++ standard library. Your compiler doesn't "recognize" this function because it doesn't exist.

Why do you think there should be such a function?

If you want to print an error message in C++, the usual method is to use the cerr stream:

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

推荐阅读