Accelerated C++ 第三章要点

Accelerated C++ 第三章要点

 

Local variables are default-initialized if they are defined without an explicit initializer. Default-initialization of a built-in type means that the value is undefined. Undefined values may be used only as the left-hand side of an assignment.
如果局部变量没有显示初始化,则踏实默认初始化的。内置类型的默认初始化意味着它的值是未定义的。未定义的值只可以用在赋值操作符的左边。

 

Type definitions:
类型定义:

 

typedef type name;   Defines name as a synonym for type.
typedef type name;   定义 name 为 type 的同义词。

 

The vector type, defined in <vector>, is a library type that is a container that holds a sequence of values of a specified type, vectors grow dynamically. Some important operations are:
定义在<vector>中的vector,是标准库定义的一种类型,它是一种能够存储某种指定类型的值序列的容器,vector是动态增长的。一些重要操作如下:

 

vector<T>::size_type
A type guaranteed to be able to hold the number of elements in the largest possible vector.
一种可以存储最大的vector的元素数量的类型,unsigned类型。

 

v.begin()
Returns a value that denotes the first element in v.
返回一个值,它指向v中的第一个元素(迭代器类型)。

 

v.end()
Returns a value that denotes (one past) the last element in v.
返回一个值(还是迭代器),它指向v中最后一个元素的下一个位置。

 

vector<T> v;
Creates an empty vector that can hold elements of type T.
创建一个存储元素类型为 T 的空vector。

 

v.push_back(e)
Grows the vector by one element initialized to e.
使vector增长一个元素,此元素被初始化为e(此元素加载v的最后)

 

v[i]
Returns the value stored in position i.
返回存储在位置i的值。

 

v.size()
Returns the number of elements in v.
返回v的元素数量。

 

Other library facilities
其他库功能

 

sort(b, e)
Rearranges the elements defined by the range [b, e) into nondecreasing order. Defined in <algorithm>.
以非递减的顺序重新排列[b, e)区间的元素。在<algorithm>中定义。

 

max(el, e2)
Returns the larger of the expressions e1 and e2; e1 and e2 must have exactly the same type. Defined in <algorithm>.
返回e1和e2之中较大的那一个;e1和e2必须具有完全相同的类型。在<algorithm>中定义。

 

while (cin >> x)
Reads a value of an appropriate type into x and tests the state of the stream. If the stream is in an error state, the test fails; otherwise, the test
succeeds, and the body of the while is executed.
读取合适类型的值到x并测试流的状态。如果流处于一种错误状态,测试失败;否则,测试成功并且while的语句会被执行。

 

s.precision(n)
Sets the precision of stream s to n for future output (or leaves it unchanged if n is omitted). Returns the previous precision.
设置流s的精度为n(或者当n未给出是不做改变),在以后的输出中起作用。返回以前的精度值。

 

setprecision(n)
Returns a value that, when written on an output stream s, has the effect of calling s.precision(n). Defined in <iomanip>.
当在输出流s上调用时,与调用s.precision(n)作用一样,返回一个值。在<iomanip>定义。

 

streamsize
The type of the value expected by setprecision and returned by precision. Defined in <ios>.
setprecision期待的值类型,precision也返回此类型,在<ios>定义。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值