[ACCEPTED]-cerr is undefined-c++
Accepted answer
You must include iostream
in order to use cerr
.
See 1 http://en.cppreference.com/w/cpp/io/basic_ostream.
You need to add this at the top :
#include <iostream>
for cerr 1 and endl
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.
#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
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.