This question already has answers here: Check if ostream object is cout or ofstream, c++ (4个答案) 3年前关闭。 我对编码有点陌生,需要为某种数据库做一个程序。我在youtube上看到了一个关于花花公子的教程,复制了他的代码,但是出现错误,并且我不知道如何解决。错误:没有运算符“==”与这些操作数匹配;引用if(outs == cout)这是代码:void Employee::output(ostream& outs){ if (outs == cout) { outs << "Name: " << name << endl; outs << "ID number: " << id_number << endl; outs << "Address: " << address << endl; outs << "Salary: " << salary << endl; outs << "Years worked at company: " << year_started << endl; } else { outs << name << endl; outs << id_number << endl; outs << address << endl; outs << salary << endl; outs << year_started << endl; }}这是我声明输出的方式:void output(std::ostream& outs);用#include 添加了iostream和字符串 最佳答案 流对象不可比较,但是您可以比较它们的地址: if ( & outs == & cout )关于c++ - C++,错误: “no operator ” == “matches these operands ”,ostream/istream ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43331766/
10-12 04:18