windows中的visual studio固然强大,但是对于平时测试用的小程序来说,建立一个工程毕竟是麻烦的。相对来说用g++在命令行下进行编译就方便多了(当然也可以用cl.exe),找到了这么一个工具,cygwin-b20,比较小巧实用。从这里下载
安装及使用方法:
直接使用可执行文件full.exe进行安装,安装目录建议选择默认路径。安装完成后,将路径C:\cygnus\cygwin-b20\H-i586-cygwin32\bin加入的系统环境变量PATH中,这样,你可以在任何目录下执行bin/的命令,其中包含了169个较为常用的linux命令。为了测试,打开cmd,建立一个文件夹fortest:mkdir fortest,进入fortest,用vim编辑(如果你安装了gvim.exe的话)一个C++文件test.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int
main()
{
	vector<string> str_vec;
	str_vec.push_back("hello,");
	str_vec.push_back("world\n");
	cout<<str_vec[0] + str_vec[1]<<endl;
	return 0;
}

建立一个Makefile文件:

1
2
test:test.cpp
	g++ test.cpp -o test.exe

执行命令:make
编译成功后,运行test.exe即可看到程序成功输出

hello,world

如果编译是提示错误:/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open output file test.exe: Permission denied.
说明g++对test.cpp所在目录没有写权限。换一个目录即可(windows下面修改权限比较麻烦^_^)。

Tags: ,,,.
你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Home

RFC: Request For Comments. Orz..

Name(required)
Mail (required),(will not be published)

RFC: Request For Comments. Orz..

Website(recommended)