!= operator and file streams

前端 未结 1 934
时光取名叫无心
时光取名叫无心 2021-01-04 20:57
#include 
#include 

using namespace std;

int main()
{

    ifstream file0( \"file0.txt\" );
    ifstream file1( \"file1.txt\" );

           


        
相关标签:
1条回答
  • 2021-01-04 21:24

    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.

    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].

    0 讨论(0)
提交回复
热议问题