!=操作符和文件流 [英] != operator and file streams
问题描述
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream file0( "file0.txt" );
ifstream file1( "file1.txt" );
if (file0 != file1) {
cout << "What is being compared?" << endl;
}
}
如果上述代码,在条件?我相信这是指针值,但我无法找到支持证据。
If the above code, what is being compared in the conditional? I believe it is pointer values but I am unable to find supporting evidence.
谢谢!
推荐答案
当对ifstream进行比较时,将调用 operator void *
。如果你使用visual studio,你可以看到这个,如果你选择看到反汇编的代码。
When doing a comparison on an ifstream the operator void*
will be called. If you are using visual studio you can see this if you choose to see the disassembly of the code.
可以找到操作符此处。
正如你可以看到的那样:
The operator can be found here. As you can see mentioned:
返回的指针不是要被引用,错误标志设置。
The pointer returned is not intended to be referenced, it just indicates success when none of the error flags are set.
因此,如果两个ifstreams失败,它们将是相等的。如果他们成功了(虽然我不知道指针值来自哪里),他们将不相等[这已经在VS上测试]。
So if both ifstreams fail, they will be equal. If they succeed (although I am not sure where the pointer value comes from) they will not be equal [this has been tested on VS].
这篇关于!=操作符和文件流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!