Cplusplus 简明教程
C++ Environment Setup
Local Environment Setup
如果您仍然愿意为 C++ 设置环境,您需要在计算机上安装以下两个软件。
If you are still willing to set up your environment for C++, you need to have the following two softwares on your computer.
Text Editor
这将用于键入您的程序。一些编辑器的示例包括 Windows 记事本、OS 编辑命令、Brief、Epsilon、EMACS 以及 vim 或 vi。
This will be used to type your program. Examples of few editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
在不同的操作系统上,文本编辑器的名称和版本会不同。例如,记事本将用于 Windows,vim 或 vi 可以用于 Windows、Linux 或 UNIX。
Name and version of text editor can vary on different operating systems. For example, Notepad will be used on Windows and vim or vi can be used on windows as well as Linux, or UNIX.
您使用编辑器创建的文件称为源文件,对于 C++,它们通常使用扩展名 .cpp、.cp 或 .c。
The files you create with your editor are called source files and for C++ they typically are named with the extension .cpp, .cp, or .c.
应该准备一个文本编辑器来启动您的 C++ 编程。
A text editor should be in place to start your C++ programming.
C++ Compiler
这是一款真正的 C++ 编译器,它将用于将源代码编译为最终可执行程序。
This is an actual C++ compiler, which will be used to compile your source code into final executable program.
大多数 C++ 编译器不关心您为源代码提供的扩展名,但是如果您不另行指定,许多编译器默认使用 .cpp。
Most C++ compilers don’t care what extension you give to your source code, but if you don’t specify otherwise, many will use .cpp by default.
最常用且免费提供的编译器是 GNU C/C++ 编译器,否则如果您拥有相应的操作系统,您可以拥有来自 HP 或 Solaris 的编译器。
Most frequently used and free available compiler is GNU C/C++ compiler, otherwise you can have compilers either from HP or Solaris if you have the respective Operating Systems.
Installing GNU C/C++ Compiler
UNIX/Linux Installation
如果您使用 Linux or UNIX ,则通过从命令行输入以下命令来检查您的系统上是否已安装 GCC:−
If you are using Linux or UNIX then check whether GCC is installed on your system by entering the following command from the command line −
$ g++ -v
如果您已安装 GCC,则它应打印如下所示的消息:−
If you have installed GCC, then it should print a message such as the following −
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr .......
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
如果未安装 GCC,则您将不得不使用 https://gcc.gnu.org/install/ 中提供的详细说明自己安装它。
If GCC is not installed, then you will have to install it yourself using the detailed instructions available at https://gcc.gnu.org/install/
Mac OS X Installation
如果您使用 Mac OS X,获取 GCC 最简单的方法是从 Apple 网站下载 Xcode 开发环境并按照简单的安装说明进行操作。
If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode development environment from Apple’s website and follow the simple installation instructions.
Xcode 目前可在 developer.apple.com/technologies/tools/ 处获得。
Xcode is currently available at developer.apple.com/technologies/tools/.
Windows Installation
要在 Windows 上安装 GCC,您需要安装 MinGW。要安装 MinGW,请访问 MinGW 主页 www.mingw.org ,并按照链接访问 MinGW 下载页面。下载最新版本的 MinGW 安装程序,其名称应为 MinGW-<version>.exe。
To install GCC at Windows you need to install MinGW. To install MinGW, go to the MinGW homepage, www.mingw.org, and follow the link to the MinGW download page. Download the latest version of the MinGW installation program which should be named MinGW-<version>.exe.
在安装 MinGW 时,您至少必须安装 gcc-core、gcc-g++、binutils 和 MinGW 运行时,但您可能希望安装更多。
While installing MinGW, at a minimum, you must install gcc-core, gcc-g++, binutils, and the MinGW runtime, but you may wish to install more.
将 MinGW 安装的 bin 子目录添加到 PATH 环境变量,这样你就可以在命令行上用这些工具的简短名称指定它们。
Add the bin subdirectory of your MinGW installation to your PATH environment variable so that you can specify these tools on the command line by their simple names.
安装完成后,你将可以使用 Windows 命令行来运行 gcc、g++、ar、ranlib、dlltool 以及其他一些 GNU 工具。
When the installation is complete, you will be able to run gcc, g++, ar, ranlib, dlltool, and several other GNU tools from the Windows command line.