C++ wstringstream的问题

C++ wstringstream的问题,c++,string,C++,String,我有一个wstringstream: wstringstream sstream; AlterSstream(sstream); wstringstream bar_stream; bar_stream << sstream; bar_stream << "foo"; MessageBoxW( NULL, bar_stream.str().c_str(), L"subject", MB_OK ); 交替流: void AlterSstream(ws

我有一个wstringstream:

wstringstream sstream;
AlterSstream(sstream);

wstringstream bar_stream;

bar_stream << sstream;
bar_stream << "foo";

MessageBoxW(
  NULL,
  bar_stream.str().c_str(),
  L"subject",
  MB_OK
);
交替流:

void AlterSstream(wstringstream& outStream)
{
    outStream << "odp";
}
void交替流(wstringstream和outStream)
{

扩展您是否尝试过
L“odp”

看起来编译器选择了
操作符的版本从一个流复制到另一个流没有重载。
您需要更改行:

bar_stream << sstream;

bar\u-stream好的,通过更新您发现了问题:


bar_stream您确定
AlterssStream
没有添加“0000000000 2CEC58”吗对于流?@GMan和@RSK-updatedI的想法是一样的,但是为什么编译器要为sstream选择正确的重载呢?另一方面,如果编译器在
alterstream
中使用
void*
版本,那么它也应该选择该版本来插入
foo
。我没有解释这个差异不同的行为。你确定你在问题中复制并粘贴了真实的代码吗?事实上,我没有完全正确地复制代码。我已经更正了操作。
outStream << L"odp";
bar_stream << sstream;
bar_stream << sstream.str();
typedef basic_stringstream<wchar_t> wstringstream;
wstringstream bar_stream( sstream.str() ) ;