编个一程序判断两个字符串是否相等。要求重载“==”运算符。
输入两个字符串str1,str2:
1234
abcd
输出比较结果:
str1!=str2
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
class Bijiao
{ char b[20];
public:
Bijiao(){gets(b);}
friend int operator==(Bijiao &b1,Bijiao&b2);
};
int operator==(Bijiao &b1,Bijiao&b2)
{
if(strcmp(b1.b,b2.b)==0)
return 1;
else
return 0;
}
int main()
{
Bijiao b1,b2;
if(b1==b2)
cout<<"str1=str2"<<endl;
else
cout<<"str1!=str2"<<endl;
}