C++ 为什么是C++;编译器不';t提供过载插入器&;类的提取器函数?

C++ 为什么是C++;编译器不';t提供过载插入器&;类的提取器函数?,c++,operator-overloading,iostream,ostream,istream,C++,Operator Overloading,Iostream,Ostream,Istream,考虑以下程序 #include <iostream> using std::ostream; using std::cout; using std::istream; using std::cin; class three_d { int i,j,k; public: three_d(int a,int b,int c) : i(a),j(b),k(c) { } //friend ostream& operato

考虑以下程序

#include <iostream>
using std::ostream;
using std::cout;
using std::istream;
using std::cin;
class three_d {
    int i,j,k;
    public:
        three_d(int a,int b,int c) : i(a),j(b),k(c)
        { }
        //friend ostream& operator << (ostream&,const three_d&);
        //friend istream& operator >> (istream&,three_d&);
};
/*ostream& operator << (ostream& o,const three_d& t) {
    o<<t.i<<", ";
    o<<t.j<<", ";
    o<<t.k<<"\n";
    return o;
}
istream& operator >> (istream& stream,three_d &t) {
    cout<<"Enter x,y,z values";
    stream>>t.i>>t.j>>t.k;
    return stream;
}*/
int main() {
    three_d a(1,2,3),b(4,5,6),c(7,8,9);
    cout<<a<<b<<c;
    cin>>a;
    cout<<a;
}
#包括
使用std::ostream;
使用std::cout;
使用std::istream;
使用std::cin;
三班{
int i,j,k;
公众:
三(inta,intb,intc):i(a),j(b),k(c)
{ }
//friend ostream&operator>(istream&,three_d&);
};
/*奥斯特雷姆算子

那么为什么>>&很少有机会流式处理类的对象状态,否则所有默认函数的概率都很高。对于您提到的运算符,默认行为通常是显而易见的。对于
来说,它不是。为什么要这样做?如果您明确地没有提供istream/ostream来满足安全性或实时性要求,该怎么办?@meet:“我想要一种语言中的X”问题是不受欢迎的,因为答案通常只是“因为您没有考虑到这样做有多难”。@meet我会问您——这个“操作符”应该做什么@meet:还有很多{embedded}不使用流的系统。不是每个平台都是桌面平台,其中也不是每个平台都写入流。此外,许多结构和类也没有写入流。
*[Error] no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'three_d')

[Error] no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'three_d')*