vs2010输出log日志到txt文件

13 篇文章 0 订阅
[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]
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);
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值