我有一個持有對stringstream的引用的類(用作整個應用程序日誌)。如何將文本添加到引用的字符串流?運算符<<和std :: stringstream引用?
爲例(因爲我不能在這裏張貼實際源...)
主要
stringstream appLog;
RandomClass myClass;
.....
myClass.storeLog(&applog);
myClass.addText("Hello World");
cout << appLog.str().c_str() << endl;
RandomClass CPP
void RandomClass::storeLog(stringstream *appLog)
{
m_refLog = appLog;
}
void RandomClass::addText(const char text[])
{
m_refLog << text; //help here...?
}
我使用的是發現了以下錯誤在我真正的應用程序非常類似於上面的設置和方法結構。 error C2296: '<<' : illegal, left operand has type 'std::stringstream *'
error C2297: '<<' : illegal, right operand has type 'const char [11]'
我知道錯誤是因爲我使用的引用,並仍試圖做「< <」,但怎麼回事我該怎麼辦呢? m_refLog-><<
???
更好地檢查它是否爲空,並在構造函數中將它初始化爲null。 – Benoit 2011-05-09 13:02:04
@Benoit更新 – asami 2011-05-09 13:17:45