|
以下是引用weikie在2006-5-23 21:22:00的发言:
#include<iostream>
#include<string>
using namespace std;
class person{
private:
string name,address;
char sex;
int ID;
public:
person(){name="king";address="09109";sex='M';ID=109;}
person(string name1,string address1,char sex1,int ID1);
void New_set();
void out_message();
friend ostream& operator<<(ostream& stream,person& p);
friend istream& operator>>(istream& stream,person& p);
};
void person::out_message()
{
cout<<"姓 名:"<<name<<endl;
cout<<"性 别:"<<sex<<endl;
cout<<"地 址:"<<address<<endl;
cout<<"身份证号:"<<ID<<endl;
}
person::person(string name1,string address1,char sex1,int ID1)
{
name=name1;
address=address1;
sex=sex1;
ID=ID1;
}
void person::New_set()
{
cout<<"请输入姓名:";
cin>>name;
cout<<"请输入地址:";
cin>>address;
cout<<"请输入性别:";
cin>>sex;
cout<<"请输入身份证号:";
cin>>ID;
}
ostream& operator<<(ostream& stream,person& p)
{
p.out_message();//流对象是stream,但是你这里是把数据插入到流对象cout中
return stream;//现在stream对象中,什么都没有
}
istream& operator>>(istream& stream,person& p)
{
p.New_set();//流对象是stream,但是你这里是把数据插入到流对象cin中
return stream;//现在stream对象中,什么都没有
}
void main()
{
person A;
cout<<A<<endl;
cout<<"请输入更新后的信息:"<<endl;
cin>>A;
cout<<A<<endl;
}
运行结果:
--------------------Configuration: Cpp2 - Win32 Debug--------------------
Compiling...
Cpp2.cpp
E:\C++\I-O流实验\Cpp2.cpp(63) : error C2593: 'operator <<' is ambiguous
E:\C++\I-O流实验\Cpp2.cpp(65) : error C2593: 'operator >>' is ambiguous
E:\C++\I-O流实验\Cpp2.cpp(66) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
Cpp2.exe - 3 error(s), 0 warning(s)
哪个大虾帮忙看下撒
以前都没问题的啊~~~ |
|