class test
{
private:
int x;
public:
friend istream& operator >>(istream & stream,test &other)
{
cout << "test input" << endl;
other.x = 100;
return stream;
}
friend ostream& operator <<(ostream &stream, test &other)
{
cout << "test:\t" << other.x << endl;
return stream;
}
};
int main()
{
test t;
cout << t;
cin >> t;
cout << t;
return 0;
}
重载输入输出运算符
最新推荐文章于 2024-02-29 17:51:21 发布