所以我的代码编译正常 - 但它不是做什么,我希望:(C++超载<<再次
生病尝试,并解释这是尽我所能 -
下面是我的代码,被写入到磁盘上的文件。
void NewSelectionDlg::PrintInfoFile()
{
**CProductListBox b;**
ofstream outdata;
outdata.open("test.dat", ios::app); // opens the file & writes if not there. ios:app - appends to file
if(!outdata)
{ // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
outdata << m_strCompany << endl;
outdata << m_strAppState << endl;
outdata << m_strPurpose << endl;
outdata << m_strChannel << endl;
outdata << m_strProductName << endl;
**outdata << b << endl;**
outdata << endl;
outdata.close();
return;
}
关键线即时关注以粗体显示。我想打印出来的一类CProductListBox。现在因为这不是一个字符串,等我知道我必须高估乘坐< <为了能够做到这一点。所以我的班级CProductList盒看起来是这样的:
class CProductListBox : public CListBox
{
DECLARE_DYNAMIC(CProductListBox)
public:
CProductListBox();
virtual ~CProductListBox();
**friend std::ostream& operator<< (std::ostream& o, const CProductListBox& b)
{
return o;
}**
我又是什么,我认为加粗是很重要的 - 这是印刷没事就输出文件不幸被我希望它会打印什么是B中的contenets(在CProductList类) 。
有人能看到一些愚蠢的事我可能会丢失 - 非常感谢,
Colly(爱尔兰)
你`运营商<<`没有做任何事情;如果你想将数据写入流,你需要编写的代码将数据写入到流... – 2011-02-15 16:48:29