重载操作符简例
#include<stdio.h>
//使out类实现一部分类似cout的功能
class out
{
public:
out& operator <<(const int value)
{
printf("%d", value);
return *this;
}
out& operator <<(const short value)
{
printf("%d", value);
return *this;
}
out& operator <<(const double value)
{
printf("%f", value);
return *this;
}
out& operator <<(const float value)
{
printf("%f", value);
return *this;
}
out& operator <<(const char *value)
{
printf("%s", value);
return *this;
}
out& operator <<(const char value)
{
printf("%c", value);
return *this;
}
};
int main()
{
out zout;
zout<<1<<"hahahaha"<<'\n';
return 0;
}