Jason's blog
We have so many needs in our life, but at the end of the day, all we need is...to be needed.

.NET在调用C++做的exe的时候,调试跟不进去,只好在各行添加日志以记录执行到哪里了。

首先添加以下引用

#include <fstream>
#include <iostream>

代码中使用时:

        std::ofstream in;
        in.open("D:\\cmdlinelog.txt",std::ios::trunc);
        in<<"program started.\n";
        in.close();

先定义文件流,并打开对应的文件(如果不存在则会创建),参数trunc是指打开并清空,如果不想清空,可以使用app参数。

执行完成后记得close(),否则如果程序出错,很有可能所有写入都不会保存进去。

posted on 2011-07-05 11:00  Jason .Z  阅读(449)  评论(0编辑  收藏  举报