[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]
CStrings represent TCHAR strings.[/color]
[/size]
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]
ofile << CT2A(str);
[size=medium][color=blue]ofstream formatted output functions expect narrow/ansi strings.
CStrings represent TCHAR strings.[/color]
[/size]
//log输出;
#include <iostream>
#include <iomanip>
#include <fstream>
//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<<logStr; //错误
outfile<<CT2A(logStr);
outfile.close();
}
fclose(fp);
}