_CrtDbgReport: String too long or IO Error

_CrtDbgReport: String too long or IO Error

 

wprintf_s不能正常出中文的解决

使用如下方法wprintf_s出中文往往出现带?的乱:

wprintf_s(L"%s",(LPCWSTR)cmdLineArr[1]);

 解决方案:包含文件locale.h,并在程序开始setlocale(LC_ALL, "chs");

这样wprintf_s便能正常打印出中文字符串了:

 //指定当前程序的编码为简体中文,这样才能用wprintf正确出中文

#include <locale.h>
setlocale(LC_ALL, "chs");

样对TRACE(_T("第一个:%s,第二个:%s"),str1,str2);,如果运行出信息:“_CrtDbgReport: String too long or IO Error”。亦可用上述方法解决。

 

TRACE在定义时就已考unicode,所以不需要加_T

可以采用OutputDebugString()来代替TRACE,它自采用UNICODE和非UNICODE

 

Microsoft Visual Studio Feedback上的反馈

http://connect.microsoft.com/VisualStudio/feedback/details/425215/bug-with-trace-and-crtdbgreport

There is a bug with TRACE and _CrtDbgReport when working with the wide string.
_CrtDbgReport can't handle the wide string correctly when the wide string contains non-ascii characters.

貌似在Beta 2 of Visual Studio 2010.修正了该bug

原文地址:https://www.cnblogs.com/BeyondTechnology/p/1931533.html