最后看一下,右移运算符的重载,右移运算符我们也常叫它输入运算符号,对于它来说,具体实现和左移运算符的重载差别并不大,对于有多成员对象的类来说,只要保证能够完整输入各成员对象大数据就可以了。
示例如下:
//程序作者:管宁
//站点:www.cndev-lab.com
//所有稿件均有版权,如要转载,请务必著名出处和作者
#include<iostream>
usingnamespacestd;
classTest
{
public:
Test(intage=0,char*name="")
{
Test::age=age;
strcpy(Test::name,name);
}
voidinputmembers(istream&out)
{
cout<<"pleaseinputage:";
cin>>Test::age;
cout<<"pleaseinputname:";
cin>>Test::name;
}
friendistream&operator>>(istream&,Test&);
public:
intage;
charname[50];
};
istream&operator>>(istream&input,Test&temp)
{
temp.inputmembers(input);
returninput;
}
intmain()
{
Testa;
cin>>a;
cout<<a.age<<"|"<<a.name<<endl;
system("pause");
}浏览URL http://www.qqread.com/cpp/p351499.html 相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- C/C++技术专题 (1640篇文章)
- 在Ubuntu 7.10中用终端编译运行C++程序 (0次浏览)
- C与C++在Linux下的集成问题 (0次浏览)
- 浅析C++中虚函数的调用及对象内部布局 (0次浏览)
- 在C++中实现四种进程或线程同步互斥的控制 (0次浏览)
- Ubuntu下面的C语言代码检查工具 Splint (0次浏览)



