• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
BeyondTechnology
博客园    首页    新随笔    联系   管理    订阅  订阅

_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

posted @ 2011-01-09 23:25  BeyondTechnology  阅读(9199)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3