在微软的Visual Studio开发环境(如VS2010)下开发C++的Console Application的项目,标准输出信息(如std::cout、printf等)都是输出到控制台的(也就是传说中的黑窗)。有很多人是不喜欢这个黑窗口的,特别是习惯了像Eclipse这样的IDE的同志,如从Java转到C++的程序员,总想把输出信息集成到VS中。其实是有一种方式可以实现这种需求的,也就是把输出信息打印到在VS的output中,下面以VS2010为例进行说明。
选择你的项目,右键property->Configuration Properties->Build Events->Post-Build Event,在右方窗口的Command Line栏中输入你编译好的exe文件的路径。如我的C++Test工程在E:\C++Workspace\VS2010\C++Test下,则在Command Line栏中输入E:\C++Workspace\VS2010\C++Test\Debug\C++Test.exe。当然你的build的输出路径有可能会改变,为避免Build输出路径改变后重新更改Command Line的值,可以输入$(OutDir)$(ProjectName).exe,和E:\C++Workspace\VS2010\C++Test\Debug\C++Test.exe的作用相同。
这样build结束后自动执行该exe程序,将程序输出信息打印到VS的output窗口中,不需要再按F5执行run。
如我的程序:
#include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; printf("Print Hello World!"); return 0; }
output窗口的输出信息:
1>------ Build started: Project: C++Test, Configuration: Debug Win32 ------
1>Build started 2015/3/7 18:35:27.
1>InitializeBuildStatus:
1> Creating "Debug\C++Test.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> All outputs are up-to-date.
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Manifest:
1> All outputs are up-to-date.
1>LinkEmbedManifest:
1> All outputs are up-to-date.
1> C++Test.vcxproj -> E:\C++Workspace\VS2010\C++Test\Debug\C++Test.exe
1>CopyFilesToOutputDirectory:
1> Copying file from "Debug\C++Test.pdb" to "E:\C++Workspace\VS2010\C++Test\Debug\C++Test.pdb".
1>PostBuildEvent:
1> Hello World!
1> Print Hello World!
1>FinalizeBuildStatus:
1> Deleting file "Debug\C++Test.unsuccessfulbuild".
1> Touching "Debug\C++Test.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:01.42
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
原文地址:http://blog.csdn.net/luoweifu/article/details/44118513