gpt4 book ai didi

c++ - cerr 未定义

转载 作者:可可西里 更新时间:2023-11-01 18:01:14 26 4
gpt4 key购买 nike

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

  • 标识符“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
}

最佳答案

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

关于c++ - cerr 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4069024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com