C++ VS 2008中的不可预测行为 ostream m_msgStream; m_msgStream.seekp(0); m_msgStream

C++ VS 2008中的不可预测行为 ostream m_msgStream; m_msgStream.seekp(0); m_msgStream,c++,visual-studio-2008,stl,C++,Visual Studio 2008,Stl,ostream已被弃用。改用std::ostringstream ostrstream m_msgStream; m_msgStream.seekp(0); m_msgStream << "Hello"; m_msgStream << ends; char *str = m_msgStream .str(); #包括 标准::ostringstream m_msgStream; 这基本上是正确的。总而言之,您必须使用m_msgStream.str().c_str(),

ostream
已被弃用。改用
std::ostringstream

ostrstream  m_msgStream;
m_msgStream.seekp(0);
m_msgStream << "Hello";
m_msgStream << ends;
char *str = m_msgStream .str();
#包括
标准::ostringstream m_msgStream;

这基本上是正确的。总而言之,您必须使用
m_msgStream.str().c_str()
,否则您将得到一个std::string而不是char*.m_msgStream().str();仅返回字符*。
#include <sstream>
std::ostringstream m_msgStream;
m_msgStream << "Hello";
std::string str = m_msgStream().str();
const char* cstr = str.c_str();