Team LiB
Previous Section Next Section

Part I: The Basics

第一部分 基本语言

Programming languages have distinctive features that determine the kinds of applications for which they are well suited. They also share many fundamental attributes. Essentially all languages provide:

各种程序设计语言都具有许多独具特色的特征,这些特征决定了用每种语言适合开发哪些类型的应用程序。程序设计语言也有一些共同的特征。基本上所有的语言都要提供下列特征:

  • Built-in data types such as integers, characters, and so forth

    内置数据类型,如整型、字符型等。

  • Expressions and statements to manipulate values of these types

    表达式和语句:表达式和语句用于操纵上述类型的值。

  • Variables, which let us give names to the objects we use

    变量:程序员可以使用变量对所用的对象命名。

  • Control structures, such as if or while, that allow us to conditionally execute or repeat a set of actions

    控制结构:如 ifwhile,程序员可以使用控制结构有条件地执行或重复执行一组动作。

  • Functions that let us abstract actions into callable units of computation

    函数:程序员可以使用函数把行为抽象成可调用的计算单元。

Most modern programming languages supplement this basic set of features in two ways: They let programmers extend the language by defining their own data types, and they provide a set of library routines that define useful functions and data types not otherwise built into the language.

大多数现代程序语言都采用两种方式扩充上述基本特征集:允许程序员通过自定义数据类型扩展该语言;提供一组库例程,这些例程定义了一些并非内置在语言中的实用函数和数据类型。

In C++, as in most programming languages, the type of an object determines what operations can be performed on it. Depending on the type of the objects involved, a statement might or might not be legal. Some languages, notably Smalltalk and Python, check the types involved in expressions at run time. In contrast, C++ is a statically typed language; type-checking is done at compile time. As a consequence, the compiler must be told the type of every name used in the program before that name can be used.

和大多数程序设计语言一样,C++ 中对象的类型决定了该对象可以执行的操作。语句正确与否取决于该语句中对象的类型。一些程序设计语言,特别是 Smalltalk 和 Python,在运行时才检查语句中对象的类型。相反,C++ 是静态类型(statically typed)语言,在编译时执行类型检查。结果是程序中使用某个名字之前,必须先告知编译器该名字的类型。

C++ provides a set of built-in data types, operators to manipulate those types, and a small set of statements for program flow control. These elements form an alphabet with which many large, complex real-world systems can and have been written. At this basic level, C++ is a simple language. Its expressive power arises from its support for mechanisms that allow the programmer to define new data structures.

C++ 提供了一组内置数据类型、操纵这些类型的操作符和一组少量的程序流控制语句。这些元素形成了一个“词汇表”,使用这个词汇表可以而且已经编写出许多大型、复杂的实际系统。从这个基本层面来看,C++ 是一门简单的语言。C++ 的表达能力是通过支持一些允许程序员定义新数据结构的机制来提升的。

Perhaps the most important feature in C++ is the class, which allows programmers to define their own data types. In C++ such types are sometimes called "class types" to distinguish them from the types that are built into the language. Some languages let programmers define data types that specify only what data make up the type. Others, like C++, allow programmers to define types that include operations as well as data. One of the primary design goals of C++ is to let programmers define their own types that are as easy to use as the built-in types. The Standard C++ library uses these features to implement a rich library of class types and associated functions.

可能 C++ 中最重要的特征是类(class),程序员可以使用类自定义数据类型。C++ 中这些类型有时也称为“类类型(class type)”,以区别于语言的内置类型。有一些语言允许程序员定义的数据类型只能指定组成该类型的数据。包括 C++ 在内的其他语言允许程序员定义的类型不仅有数据还包括操作。C++ 主要设计目标之一就是允许程序员自定义类型,而且这些类型和内置类型一样易于使用。C++ 标准库复用这些特征,实现了一个具有丰富类型和相关函数的标准库。

The first step in mastering C++learning the basics of the language and libraryis the topic of Part I. Chapter 2 covers the built-in data types and looks briefly at the mechanisms for defining our own new types. Chapter 3 introduces two of the most fundamental library types: string and vector. Arrays, which are covered in Chapter 4, are a lower-level data structure built into C++ and many other languages. Arrays are similar to vectors but harder to use. Chapters 5 through 7 cover expressions, statements, and functions. This part concludes in Chapter 8, which covers the most important facilities from the IO library.

掌握 C++ 的第一步是学习语言的基本知识和标准库,这正是第一部分介绍的内容。第二章介绍了内置数据类型,并简单探讨了自定义新类型的机制。第三章引入了两种最基本的标准库类型:stringvector第四章介绍了数组,数组是一种低级的数据结构,内置于 C++ 和许多其他语言。数组类似于 vector 对象,但较难使用。第五章第七章介绍了表达式、语句和函数。第八章第一部分的最后一章,介绍了 IO 标准库中最重要的设施。


CONTENTS
 

Chapter 2 Variables and Basic Types

 

Chapter 3 Library Types

 

Chapter 4 Arrays and Pointers

 

Chapter 5 Expressions

 

Chapter 6 Statements

 

Chapter 7 Functions

 

Chapter 8 The IO Library


Team LiB
Previous Section Next Section