64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
class oper
{
friend std::ostream& operator<<(std::ostream& os, const oper& obj) // 返回值后面有个&
{
os << obj.data <<std::endl ;
return os ;
}
private :
int data;
};
#include <iostream>
class oper
{
public :
oper() : data(0) {}
oper(int i) : data(i) {}
void show()
{
std::cout << "the data is " << data << std::endl;
}
friend std::ostream& operator<<(std::ostream& os, const oper& obj)
{
os << obj.data <<std::endl ;
}
friend std::istream& operator>>(std::istream& is , oper& obj)
{
is >> obj.data ;//cin >> 后只跟变量 char ch ,,,
}
private :
int data;
};
int main()
{
oper obj1(10), obj2(12);
std::cout << obj1 << obj2;
std::cin.get();
ostream cout(stdout);//其默认指向的C中的标准设备名,作为其构造函数的参数使用。
ostream& operator<<(ostream &out,int rhs);
ostream& operator<<(ostream &out,char *rhs);
//等等
#include <iostream>
class oper
{
public :
oper() : data(0) {}
oper(int i) : data(i) {}
void show()
{
std::cout << "the data is " << data << std::endl;
}
friend std::ostream& operator<<(std::ostream& os, const oper& obj)
{
os << obj.data <<std::endl ;
}
friend std::istream& operator>>(std::istream& is , oper& obj)
{
is >> obj.data ;//cin >> 后只跟变量 char ch ,,,
}
private :
int data;
};
int main()
{
oper obj1(10), obj2(12);
std::cout << obj1 << " " << obj2;
std::cin.get();
}
std::cout<<oper1<<oper2;
opertator<<(operator<<(std::cout,oper1),oper2);