木易的主页
广播
相册
日记
喜欢
豆列
2013-04-09 15:34:04
C++ Primer, Fifth Edition
Pre GCC 4.7.0
Code Distribution README
Barbara E. Moo
[email protected]
August 16, 2012
************************楼主有话说分割线***********************************************************************
此为C++ Primer第五版源代码说明文档,包含在GCC_pre_C11.zip压缩包内。
C++ Primer第五版源代码下载地址:http://www.informit.com/store/c-plus-plus-primer-9780321714114
网页中包含4个源代码压缩包,分别适用于不同的编译器。
Download the source files forGCC 4.7.0.
适用于GCC 4.7.0.或更高版本GCC
Download the source code files forMS Visual Studio 2012
适用于Visual Studio 2012或更高版本
Download the source code files forGCC pre-C++ 11 compilers 2012.
适用于GCC 4.7.0之前版本,不使用c++0x或c++11的新标准。
Download the source code files forMicrosoft pre-C++ 11 compilers.
适用于Visual Studio 2012之前版本
本人的编译器版本:
[****@localhost primer]$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
所以使用GCC_pre_C11。
************************楼主有话说分割线***********************************************************************
************************以下为楼主粗略翻译*********************************************************************
Overview
This distribution contains the source code of all the complete programs and
many of the program fragments from C++ Primer. The code in this distribution
has been edited to work with pre C++11 GNU compilers. We tested this code
using the GCC 4.5.3 compiler, but it should work with earlier versions of the
compiler as well. Please see CompilerNotes.pdf in this directory for more
information on the missing features and workarounds.
概述
这 个发行版包含了C++ Primer里所有完整程序的源代码和一些代码片段。这些代码工作在C++11 GNU之前的编译器环境下。我们用GCC 4.5.3 测试过这些代码,在之前的编译器版本下也应该可以适用。请查看本目录下的CompilerNotes.pdf文档以获得更多信息。
Building Executables
构建可执行文件
The code is divided into 19 subdirectories corresponding to the Chapters in
C++ Primer. Each subdirectory contains a makefile thatmakes the source in that
directory. Thesemakefiles rely on the file named GNU makefile template in
the top-level directory. The makefiles are fairly simple and we have provided
comments in the hope that even those who are not familiar with makefiles can
understand how to compile these programs by hand if so desired.
代 码根据C++ Primer中的章节分布在19个子目录下。每个子目录包含一个makefile文件,用来make当前目录的代码。这些makefile文件都依赖顶层 目录的GNU makefile template文件。这些makefile文件都很简单,如果需要,我们还是提供了一些备注,希望那些不熟悉makefile的人也可以了解如何手工编 译这些程序。
The top level directory also has its own makefile that will make the entire
source tree. The top level makefile also has targets clean and clobber to
remove the object files or object and executable files respectively.
顶层目录中同样有自己的makefile文件,他可以make整个目录文件。这个makefile还包含了 clean and clobber两个标示,可以删除对象文件或分别删除对象文件和执行程序。
To use make on most UNIX based operating systems you invoke the command
named make:
在大多数基于UNIX的操作系统中你调用make命令:
# UNIX machines
$ make # compiles all the programs 编译所有的程序
$ make clean # removes all the object files and stackdumps 删除所有的对象文件和堆栈转储文件
$ make clobber # removes executable, object and stackdump files 删除可执行文件、对象文件和堆栈转储文件
Input and Output
输入和输出
The code in these subdirectories includes all of the complete programs covered
in C++ Primer.
这些子目录里的代码覆盖了C++ Primer所有的完整项目。
In addition, we include executable versions of some of the otherwise incomplete
program fragments. In general, such programs print details about
the internal state of the program. To understand the output, you will have to
understand the program. This is intentional.
此外,我们包含了一些其他不完整程序片段的可执行版本。一般来说,这样的程序打印了程序的内部状态的细节。为了了解输出,你将不得不去理解程序。这是故意的。
The input, if any, to these programs varies:
对于这些程序的输入,如果有的话,是不同的:
• Some programs print a prompt and wait for input on the standard input •一些程序打印一个提示,等待输入的标准输入
• Other programs read the standard input but do not print a prompt •一些程序读取标准输入但不打印一个提示
• Others take one or more arguments specifying a file name to read •另外一些带一个或多个参数来指定一个用来读取的文件名
• Yet others take a file name argument and read the standard input •但其他一些则带一个文件名参数,并读取标准输入
Each Chapter subdirectory contains a README that explains the input, if any,
expected by each executable file.
如果可执行文件期待一个输入的话,每一章的子目录包含一个README解释输入。
Sample Data Files
示例数据文件
For those programs that expect input, we have provided small, sample input
files. Input files are always found in a subdirectory named data. For example,
the program add_item in directory 1 reads Sales_item transactions from
the standard input but does not prompt for input. If the program is invoked:
add_item
it will wait for input, which you can provide by typing appropriate transactions.
Alternatively, you can pass the data file we provide. Assuming the following
is executed in the directory named 1 writing
add_item < data/add_item # UNIX
will bind the standard input to the add_item file in the data subdirectory
and will execute the program add_item on the data in that file.
Some of the programs take argument(s) that must be supplied when the
program is executed. These programs will fail if they are invoked with no
argument. For example, the word_transform program in the Chapter 11
directory requires two input files. You might invoke this program as follows:
# word_transform takes two files, samples are in the data directory
# this execution uses the file data/rules to transform the text in data/text
word_transform data/rules data/text # UNIX
See Section 1.1.1 for a description of how C++ programs are run, page 22 for
how files are bound to the standard input and standard output, and Section
6.2.5 for how arguments are passed to a C++ program.
对于那些需要输入的程序,我们提供了一个简单的实例输入文件。输入文件往往可以在子目录的data文件夹下找到。比如,目录1中的add_item程序需要从标准输入读取Sales_item交易,但不提示输入。如果程序被如下调用:
add_item
它将等待输入,您可以通过输入适当的交易提供。另外,您可以通过我们提供的数据文件。假设在目录1下执行了如下命令
add_item < data/add_item # UNIX
它会将data子目录下的add_item文件绑定到标准输出上,并在这个文件里的数据上执行add_item程序。
对于一些带参数的项目,执行时必须提供的参数列表。如果没有参数,这些程序会执行失败。例如,在第11章目录下的word_transform程序需要两个输入文件。你可能会这样调用这个程序:
# word_transform takes two files, samples are in the data directory
# this execution uses the file data/rules to transform the text in data/text
word_transform data/rules data/text # UNIX
参见1.1.1节了解c++程序是如何运行的,22页了解如何将文件绑定到标准输入和标准输出,参加6.2.5节了解如何将参数传递给一个c++程序。
Running the Programs
Each directory contains a simple shell script named runpgms that runs the
executables made in that directory.
Note that on some systems, the default setting for the PATH variable does
not include the current directory. In this case, if you try to execute
add_item < data/add_item # UNIX
the add_item program will not be found. Instead, you must write
./add_item < data/add_item # UNIX
where ./tells the system to run the add_item program in the current directory.
运行程序
每个目录包含一个名为runpgms的简单shell脚本,用来运行目录下生成的可执行文件。
请注意,在某些系统上,默认设置PATH变量不包括当前目录。这种情况下,如果你尝试执行
add_item < data/add_item # UNIX
add_item程序将不会被找到,相反,你必须写成
./add_item < data/add_item # UNIX
“./”告诉系统在当前目录下运行程序add_item