ITeye博客

vs2010输出log日志到txt文件

恶灵挽歌 · 2012-09-27 16:35 · MFC · C++ · 编程语言 · Markdown

[size=medium] android开发时,通过eclipse,可以用Logcat,也可以直接在控制台输出调试信息。而今天在vc2010上调试MFC代码时,却一时不知道怎么输出调试信息了。 google了一下,输出调试信息到文本文件(*.txt)是常用的办法。找到代码,运行,出现问题:文件里只输出一个地址值 "[color=blue]00A74B88[/color]"。有人说是Unicode编码的问题。再google,stackoverflow上有人给出了解决办法。 [color=blue]If you just want plain ACP encoded ANSI text:[/color][/size][code="C++"]ofile << CT2A(str);[/code][size=medium][color=blue]ofstream formatted output functions expect narrow/ansi strings. CStrings represent TCHAR strings.[/color] [/size] [code="C++"] //log输出; #include #include #include //other code void WriteLog(CString logStr) { FILE *fp; fp = fopen("d:\\log.txt","w+"); if ( fp == NULL ) return; ofstream outfile; outfile.open("d:\\log.txt"); if(outfile.is_open()) { // outfile<

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。