首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian >> 语言基础 >> 正文
C++的iostream标准库介绍(13)
作者:管宁    文章来源:PConline    更新时间:2006-6-1 9:11:25
最后看一下,右移运算符的重载,右移运算符我们也常叫它输入运算符号,对于它来说,具体实现和左移运算符的重载差别并不大,对于有多成员对象的类来说,只要保证能够完整输入各成员对象大数据就可以了。

  示例如下:

//程序作者:管宁   
//站点:www.cndev-lab.com   
//所有稿件均有版权,如要转载,请务必著名出处和作者   
   
#include <iostream>   
using namespace std;   
   
class Test   
{   
    public:   
        Test(int age = 0,char *name = "\0")   
        {   
            Test::age = age;   
            strcpy(Test::name,name);   
        }   
        void inputmembers(istream &out)   
        { 
            cout<<"please input age:"; 
            cin>>Test::age; 
            cout<<"please input name:"; 
            cin>>Test::name; 
        }   
        friend istreamoperator >>(istream& ,Test&);   
    public:   
        int age;   
        char name[50];   
};   
istreamoperator >>(istream& input,Test &temp)   
{   
    temp.inputmembers(input);   
    return input;   
}   
int main()      
{   
    Test a;   
    cin>>a; 
    cout<<a.age<<"|"<<a.name<<endl; 
    system("pause");   
}

相关文章:
列举系统当前所有进程
cpp命令
S60 Python 编程指南——弹出列表
S60 Python 编程指南——文本输入练习(二)
S60 Python 编程指南——文本输入练习(一)
SIS文件中的Vendor信息在软件各版本中不应更改
S60平台: 使用DBMS APIs —在DBMS中使用SQL语言(3)
Audio input streaming溢出,导致异常发生
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号