#include
using namespace std;
class F{
int n;
int d;
public:
F(int n=0,int d=1):n(n),d(d){};
friend void operator>>(istream& in,F& f);
friend void operator<<(ostream& out,const F& f);
};
void operator>>(istream& in,F& f){
char c;
in>>f.n>>c>>f.d<
void operator<<(ostream& out,const F& f){
out<
int main ()
{
F a;
cin>>a;
cout< return 0;
}
编译错误提示
:\Users\kjk\c编程\输入与输出.cpp(15) : error C2248: 'n' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(6) : see declaration of 'n'
C:\Users\kjk\c编程\输入与输出.cpp(15) : error C2248: 'd' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(7) : see declaration of 'd'
C:\Users\kjk\c编程\输入与输出.cpp(15) : error C2678: binary '<<' : no operator defined which takes a left-hand operand of type 'class std::basic_istream
C:\Users\kjk\c编程\输入与输出.cpp(18) : error C2248: 'n' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(6) : see declaration of 'n'
C:\Users\kjk\c编程\输入与输出.cpp(18) : error C2248: 'd' : cannot access private member declared in class 'F'
C:\Users\kjk\c编程\输入与输出.cpp(7) : see declaration of 'd'
C:\Users\kjk\c编程\输入与输出.cpp(23) : error C2593: 'operator >>' is ambiguous
C:\Users\kjk\c编程\输入与输出.cpp(24) : error C2593: 'operator <<' is ambiguous
执行 cl.exe 时出错.
输入与输出.exe - 1 error(s), 0 warning(s)