Visual Studio 输出窗口错误 - C++
使用 Visual Studio 2008,我不断在输出窗口中看到此错误:
_CrtDbgReport:字符串太长或 IO 错误
我的代码中散布着很多 TRACE
宏,用于转储有关错误条件的信息:文件路径、行号、错误等。我需要追踪此错误的根源,因为它尝试转储到输出窗口的信息可能太长。 TRACE
宏可以接受的字符串的最大长度是多少?以下是我通常如何使用此宏的示例:
TRACE(_T("CreateNotifyWindow : Failed to create handle for notify window thread.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), _T(__FILE__), __LINE__);
任何想法将不胜感激。谢谢。
Using Visual Studio 2008, I keep seeing this error in the output window:
_CrtDbgReport: String too long or IO Error
I have a lot of TRACE
macros scattered throughout my code used to dump information about error conditions: file path, line number, error, etc. I need to trace down the source of this error because it may be that information it is trying to dump to the output window is too long. What is the maximum length of the string the TRACE
macro can accept? Here is an example of how I typically use this macro:
TRACE(_T("CreateNotifyWindow : Failed to create handle for notify window thread.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), _T(__FILE__), __LINE__);
Any thoughts would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终我敢打赌问题是将对象字符串而不是 string.c_str() 传递给宏。 TRACE 使用可变参数传递到最终调用 vsnprintf() 系列中的某些内容来进行
%s
处理。它无法处理对象,因为C
不能。由于实现原因,OutputDebugString 的最大长度为 4K 字节减去小数。
Ultimately I'll bet the problem is passing an object string instead of string.c_str() to the Macro. TRACE uses variadic argument passing to, ultimately, something that calls something in the vsnprintf() family for
%s
processing. It cannot deal with objects becauseC
can not.The maximum length for OutputDebugString is 4K bytes minus a fraction, due to the implementation.
你和我遇到了同样的麻烦。
我在网上找到了这个问题的答案
我检查了一下,效果非常好。
现在,您可以在调试输出窗口中看到正确的宽字符串。
祝你好运!
You've got in the same trouble as I did.
I got the answer to this question on the web, and
I checked it out, which worked very well.
Now, you can see the correct wide character string on your debug output window.
Good luck!