[ACCEPTED]-cerr is undefined-c++

Accepted answer
Score: 21

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

Score: 11

You need to add this at the top :

#include <iostream>

for cerr 1 and endl

Score: 10

include iostream for cerr support.

And there 3 is no implementation of operator << for 2 class Basic. You'd have to make that implementation 1 yourself. See here.

Score: 3
#include <fstream>
#include <iostream>

#include "basic.h"


std::ostream& operator<<(std::ostream &out, Basic const &x) {
  // output stuff: out << x.whatever;
  return out;
}

int main() {
  using namespace std;

  ofstream output ("output.txt", ios::out);
  if (!output) {  // NOT comparing against NULL
    cerr << "File cannot be opened.\n";
    return 1;
  }

  output << "Opening of basic account with a 100 Pound deposit:\n";
  Basic myBasic (100);
  output << myBasic << endl;

  return 0;
}

0

More Related questions