最近自己用C++编了一个有关分数运算的小程序
这是程序中对分数的输入与输出
//numerator与denominator分别表示分子与分母
friend istream& operator>>(istream is,fraction& f);
friend ostream& operator<<(ostream os,const fraction& f);
istream& operator>>(istream& is,fraction& f)
{
char str[1];
is>>f.numerator>>str[0]>>f.denominator;
return is;
}
ostream& operator<<(ostream& os,const fraction& f)
{
os<<f.numerator<<"/"<<f.denominator;
return os;
}
//以下是编译时的错误,不是太明白,请高手指教
C:\MinGWStudio\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\c++\3.4.2\bits\ios_base.h: In copy constructor `std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':
C:\MinGWStudio\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\c++\3.4.2\bits\ios_base.h:738: error: `std::ios_base::ios_base(const std::ios_base&)' is private
main.cpp:7: error: within this context
main.cpp: In function `int main()':
main.cpp:7: error: initializing argument 1 of `std::istream& operator>>(std::istream, fraction&)'