标题:重载输入输出流,郁闷。
只看楼主
choco1024
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:183
专家分:140
注 册:2008-8-31
结帖率:100%
 问题点数:0 回复次数:0 
重载输入输出流,郁闷。
#include <iostream>
#include <string>
using namespace std;
class Student{
public:
    string szName;
    string szID;
    int age;
public:
    Student(string a="0",string b="0",int c=0){szName=a;szID=b;age=c;}
    friend istream& operator >>(istream&,Student&);
    friend ostream& operator <<(ostream&,Student&);
};
istream& operator >>(istream& input,Student& st1)
{
    cout<<"Please input the student's name,ID,age:";
    input>>st1.szName>>st1.szID>>st1.age;
    return input;
}
ostream& operator <<(ostream& output,Student& st1)
{
    output<<"the name is:"<<st1.szName<<endl;
    output<<"the ID is:"<<st1.szID<<endl;
    output<<"the age is:"<<st1.age<<endl;
    return output;
}
int main()
{
    Student st1;
    cin>>st1;
    cout<<st1;
    return 0;
}
--------------------Configuration: overload_cout - Win32 Debug--------------------
Compiling...
overload_cout.cpp
F:\C程序\Overload_cout\overload_cout.cpp(30) : error C2593: 'operator >>' is ambiguous
F:\C程序\Overload_cout\overload_cout.cpp(31) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.

overload_cout.obj - 2 error(s), 0 warning(s)
搜索更多相关主题的帖子: 重载 输出 输入 
2008-10-21 22:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-239730-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.178849 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved