Visual Studio输出窗口错误- c++

Visual Studio Output Window Error - C++

本文关键字:c++ 错误 窗口 Studio 输出 Visual      更新时间:2023-10-16

使用Visual Studio 2008,我一直在输出窗口看到这个错误:

_CrtDbgReport: String too long or IO Error

我有很多TRACE宏分散在我的代码中,用于转储有关错误条件的信息:文件路径,行号,错误等。我需要跟踪这个错误的来源,因为它可能是试图转储到输出窗口的信息太长。TRACE宏可以接受的最大字符串长度是多少?下面是我通常如何使用这个宏的一个示例:

TRACE(_T("CreateNotifyWindow : Failed to create handle for notify window thread.rntError: %drntFile: %srntLine: %drn"), ::GetLastError(), _T(__FILE__), __LINE__);

任何想法都会很感激。谢谢。

最终我敢打赌问题是传递一个对象字符串而不是string.c_str()给宏。TRACE使用可变参数传递,最终,调用vsnprintf()家族中的某些东西进行%s处理。它不能处理对象,因为C不能。

OutputDebugString的最大长度是4K字节减去一个分数,由于实现。

你和我遇到了同样的麻烦。我在网上找到了这个问题的答案,然后我检查了一下,效果很好。

// Inside your main header like stdafx.h, add the following include directive
#include <locale.h>

// And inside your main implementation such as InitInstance()
// of your CWinApp derived application class,
// you can put the following locale designation function.
#ifdef _DEBUG
_tsetlocale(LC_ALL, _T("korean")); // you should set the country code of yours
#endif // _DEBUG

现在,您可以在调试输出窗口中看到正确的宽字符串。好运!