有没有人能告诉我<<操作符。Visual studio告诉我有很多参数。Node是一个结构
ostream& operator << (ostream& strm, const node* &obj )
{
strm << "ItdID: " << obj.itemId << "nItem Description: " << obj.itemDescription << "nItem Quanity: " << obj.quanity
<< "nWholesale Cost: $" << fixed << showpoint << setprecision(2) << obj.wholesale << "nRetail Cost: $" << fixed << showpoint << setprecision(2) << obj.retail;
return strm;
}
您需要将ostream& operator << (ostream& strm, const node* &obj )
声明为friend
函数到node
类。
那么在你的节点类中你要有
friend ostream& operator << (ostream& strm, const node* &obj );
然后在你的CPP文件中有
ostream& operator << (ostream& strm, const node* &obj )
{
strm << "ItdID: " << obj.itemId << "nItem Description: " << obj.itemDescription << "nItem Quanity: " << obj.quanity
<< "nWholesale Cost: $" << fixed << showpoint << setprecision(2) << obj.wholesale << "nRetail Cost: $" << fixed << showpoint << setprecision(2) << obj.retail;
return strm;
}