- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
2年前关闭。
Improve this question
只是一个错字:
“尝试在 C++ 中打印字符串或对象时,'operator<<' (操作数类型为 '__FILE*' {aka '__sFILE64*'} 和 'MyObject' )不匹配”
通过使用 cout 解决,而不是 stdout。
但包含 Eclipse 故障排除:
(Eclipse) sources.mk not finding and including all subdirectories (Solved) by renaming a folder named headers to r_headers, deleting the sources.mk and refreshing, and then added another folder called a_test. I don't know why it wouldn't work even by closing eclipse before adding another folder, but it magically started finding all subdirectories. (Note: thjis was after using this fix: How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT?)
stdout << "hello";
直接它仍然返回
#include <iostream>
#include <string>
using std::string;
class MyObject {
private:
string s1;
string s2;
public:
MyObject();
std::ostream& operator<<(std::ostream& os,MyObject const& o);
string toString();
};
class MyObject{
string s1,s2;
MyObject(){
s1 = "hello";
s2 = "world";
}
};
std::ostream& operator<<(std::iostream& os, MyObject const& o) {
string s = toString();
os << s;
return os;
}
string toString() {
return s1+s2;
}
#include <iostream>
#include <string>
#include "../r_headers/MyObject.h"
using std::string;
using std::cout;
using std::endl;
void test_print_mo() {
MyObject o = MyObject();
//string s= MyObject.toString();
//stdout << o; **// where I initially made a typo**
cout << o; //works, solution
}
int main() {
test_print_mo();
//do not delete, make sure window doesn't close
cin.get();
return 0; //for compiler
}
最佳答案
对于初学者来说,有一个错字
class MyObject {
private:
string s1;
sting s2;
^^^^^
//...
std::ostream& operator<<(MyObject const& o);
std::ostream& operator<<(std::iostream& os, MyObject const& o) {
std::string s = toString();
os << s;
return os;
}
std::ostream& operator<<(MyObject const& o);
MyObject::MyObject(){
s1 = "hello";
s2 = "world";
}
class MyObject {
private:
string s1;
sting s2;
public:
MyObject();
std::string toString() const;
};
MyObject::MyObject() : s1( "hello" ), s2( "world" ){
}
std::string MyObject::toString() const {
return s1 + " " + s2;
}
inline std::ostream & operator<<(std::ostream& os, MyObject const& o) {
return os << o.toString();
}
std::ostream&
,而不是
std::iostream&
.
关于c++ - "no match for ' 运算符<< ' (operand types are ' __FILE* ' {aka ' __sFILE64* '} and ' MyObject ' ) error C++",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60402539/
我正在尝试为一个简单的数学 Vector 类重载 += 运算符,以对两个 vector 的元素求和,如下所示: vector1 += vector2 部分Vector2D.h: #ifndef _VE
我正在尝试在 ASM 中编写一个简单的 for 循环。我需要访问两个数组,它们是在 C++ 代码片段之外编写的(即 OrigChars 和 EncrChars) char temporary_
Qt 版本 5.01 平台 windows 64 位 问题:错误:没有操作数“ #include #include #include namespace { std::ost
#include #include #define SIGBAD(signo) ((signo) = NSIG) int sigaddset(sigset_t *set, int signo
请看下面的代码。我正在使用 Apache Derby 作为嵌入式数据库 public List getDetails(String name) { List details =
我和我的讲师/实验室助理都被难住了。 出于某种原因,以下 HLSL 代码在输出窗口中返回: error X8000 : D3D11 Internal Compiler error : Invalid
我有一个创建时间跟踪器的 NPM 包,它使用 for in 来定位 MD 文件的标题,然后将其转换为跟踪器。目前,在 Mac 上运行它时工作正常,在 Windows 上我收到 dirname:miss
请注意这个问题是不是 this 的副本或 this ,因为其他问题没有运算符(operator) 组件,不要询问我正在询问的参数和参数的详细信息。 我将使用 vb.net 教授第一门编程类(class
输入 sudo apt autoremove 后出现此错误在终端 readlink: missing operand Try 'readlink --help' for more informatio
为什么 GCC 给我这个错误?我在这里做错了什么? temp.c: In function main: temp.c:6: error: invalid operands to binary +
我对此很陌生,我正在尝试将值从一个数组移动到另一个数组, 它假设是: vec1 = 1, 2, 3, 4, 5 vec2 = 5, 4, 3, 2, 1 但我收到一个错误:“指令操作数必须是相同的大小
我有一个 OR 表达式,它应该返回不是 NaN 的操作数: (1 || NaN) // evaluates to 1 (NaN || 1) // evaluates to 1 但是当另一个操作数也是一
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 4 年前。 Improve th
这道题是基于 Javascript 的,但适用于一般的逻辑运算 拿代码举例 if (baseText[i] == "."){ /*splice array*/;} if (baseText[
我似乎无法找到使程序运行的问题。 C 告诉我“错误:二进制操作数无效!= 'grocerylist'(又名 structgrocerylist)和 'int' 当我尝试解决此问题时,会弹出其他错误,除
我正在查看 the docs并尝试了解运算符的实际工作方式。 The increment operator (++) increments its operand by 1. The incremen
我有一个很长的 json 字符串,"attributeName":"Loc ID"},"operands":["10000"]}],"Frequency":{"type":" 这个只是其中的一部分,我
目前,我尝试编译 OpenVDB,它依赖于 Threading Building Blocks。我收到以下错误: In file included from /usr/include/tbb/enum
我收到的错误: /usr/include/c++/7/bits/stl_function.h:386: error: no operator " NearestNeighbor::nearest_pa
我有一个类Color , 那有 friend std::ostream& operator void print_head(const T& head, sost& o) { o (rsym,
我是一名优秀的程序员,十分优秀!