struct ceshi
{
int frist;
int second;
ceshi(int one = 0,int two = 0):frist{one},second{two}
{
}
friend std::ostream& operator<<(std::ostream&,const ceshi&);
friend QDebug operator<<(QDebug dbg, const ceshi&);
};
std::ostream & operator << (std::ostream & os,const ceshi & c)
{
return os << "std::cout 输出 ceshi{ frist = " << c.frist << ",second = " << c.second << "}";
}
QDebug operator<<(QDebug dbg, const ceshi & c)
{
dbg.nospace() << "debug 输出 ceshi{ frist = " << c.frist <<",second = "<< c.second << "}";
return dbg;
}
#define debug qDebug()<<
int main(int argc, char *argv[])
{
ceshi c(1,2);
std::cout << c;
debug c;
}
std::cout 中文乱码......
qt有个《Custom Type Example》demo是专门介绍qDebug重载的。