我有一个持有对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