---
title: "vs2010输出log日志到txt文件"
author: "恶灵挽歌"
date: "2012-09-27T16:35:00Z"
tags: []
categories: ["编程语言"]
slug: "vs2010-log-txt"
draft: false
lastmod: "2012-09-27T16:47:17Z"
id: 1687488
url: "https://elingwange.iteye.com/blog/1687488"
---

\[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 &lt;&lt; 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&lt;