阅读背景:

判断两个结构体是否相等+是否能用memcmp函数判断结构体相等

来源:互联网 

判断两个结构体是否相等:重载操作符"=="

#include<iostream>

using namespace std;

struct s
{
	int a;
	int b;
	bool operator==(const s &rhs);
};

bool s::operator==(const s &rhs)
{
	return ((a == rhs.a) && (b == rhs.b));
}

int main()
{
	struct s s1, s2;
	s1.a = 1;
	s1.b = 2;
	s2.a = 1;
	s2.b = 2;
	if (s1 == s2)
		cout << "两个结构体相等" << endl;
	else
		cout << "两个结构体不相等" << endl;
	return 0;
}#include<iostrea



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: