cerr未定义

use*_*257 7 c++

我有一些问题,我收到这些错误(在代码中标出):

  • 标识符"cerr"未定义
  • 没有运算符"<<"匹配这些操作数

为什么?

#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
}
Run Code Online (Sandbox Code Playgroud)

小智 18

您必须包含iostream才能使用cerr.
http://en.cppreference.com/w/cpp/io/basic_ostream.


BЈо*_*вић 9

你需要在顶部添加:

#include <iostream>
Run Code Online (Sandbox Code Playgroud)

对于cerr和endl


jil*_*wit 9

包括iostream用于cerr支持.

并且没有实现operator << for Basic.你必须自己做这个实现.看到这里.