C++ 从stringstream复制输出

C++ 从stringstream复制输出,c++,debugging,stringstream,C++,Debugging,Stringstream,我很抱歉,如果它是一个重复的,我已经在搜索,所以我看到有类似的问题,但我仍然无法调试的问题 我使用stringstream进行简单的调试。 我有一个宏: #else #include <sstream> extern std::wstringstream trc; #define DEBUG_MSG(x) \ trc.str(std::wstring());\ trc<<x;\ OutputDebugString(trc.str().c_str(

我很抱歉,如果它是一个重复的,我已经在搜索,所以我看到有类似的问题,但我仍然无法调试的问题

我使用stringstream进行简单的调试。 我有一个宏:

#else 
#include <sstream>
extern std::wstringstream trc;
#define DEBUG_MSG(x) \
    trc.str(std::wstring());\
    trc<<x;\
    OutputDebugString(trc.str().c_str())
#endif 
(输出打印两次)


我做错了什么?

我记得我遇到过类似的问题,这就是OutputDebugString的问题。只需将调试类型更改为本机

VS2010

1.在解决方案资源管理器中,选择项目

2.在“视图”菜单上,单击“属性”

3.在“属性页”对话框中,展开“配置属性”节点,然后选择“调试”

4.将调试器类型设置为本机

检查下面的链接,票证已关闭,因为不可复制,但还有其他人面临类似的定位


这只是一个比赛条件问题

如果代码是这样交错的:

thread 1: trc.str(std::wstring());
thread 2: trc.str(std::wstring());
thread 1: trc<<x;
thread 1: OutputDebugString(trc.str().c_str());
thread 2: trc<<x;
thread 2: OutputDebugString(trc.str().c_str());
线程1:trc.str(std::wstring()); 线程2:trc.str(std::wstring());
线程1:trcErr。。。没有什么?“你以为会发生什么事?”马丁·詹姆斯说,他只期待一句话,却得到两句。OP:可能它被调用了两次?你是说调试消息用这个宏被打印了两次吗??除非是这样,否则我看不出输出有任何错误。我希望输出中只有一行…只需调试它。如果需要,请查看预处理的输出。我仍然存在使用本机还是自动的问题,但我认为我可以不再担心代码中有错误。顺便说一句,我会做一些其他的测试。编辑:顺便说一下,我已经完成了vs2013。更可能的场景是:线程1:trc.str(std::wstring());线程2:trc.str(std::wstring());线程1:trcNo,它将打印来自线程1的消息的2倍和来自线程2的消息的2倍(如果您不信任我,请尝试使用visual studio)
IPCFacilities: InsertCtrlMessage: write. Time: 265793562
IPCFacilities: InsertCtrlMessage: write. Time: 265793562
thread 1: trc.str(std::wstring());
thread 2: trc.str(std::wstring());
thread 1: trc<<x;
thread 1: OutputDebugString(trc.str().c_str());
thread 2: trc<<x;
thread 2: OutputDebugString(trc.str().c_str());