Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cerr is undefined

Tags:

c++

I have some problems, I'm getting these errors (marked in the code):

  • identifier "cerr" is undefined
  • no operator "<<" matches these operands

Why?

#include "basic.h"
#include <fstream>

using namespace std;

int main()
{

    ofstream output("output.txt",ios::out);
    if (output == NULL)
    {
        cerr << "File cannot be opened" << endl;   // first error here
        return 1;
    }

    output << "Opening of basic account with a 100 Pound deposit: "
        << endl;
    Basic myBasic (100);
    output << myBasic << endl;   // second error here
}
like image 673
user195257 Avatar asked Nov 01 '10 12:11

user195257


People also ask

What library is CERR in C++?

The cerr object in C++ is an object of class ostream . It is associated with the standard C error output stream stderr . The cerr object is ensured to be initialized during or before the first time an object of type ios_base::Init is constructed.

What is CERR?

cerr – Standard Error Stream Object in C++ Standard error stream (cerr): cerr is the standard error stream which is used to output the errors. It is an instance of the ostream class.


1 Answers

You must include iostream in order to use cerr.
See http://en.cppreference.com/w/cpp/io/basic_ostream.

like image 151
Mauren Avatar answered Oct 19 '22 14:10

Mauren