C++中函数备忘录

1.

int rand(void);

function: creat random value ,从srand(seed)中指定的seed开始,返回一个[seed,RAND_MAX(0X7fff)]间的随机整数

void srand(unsigned seed);

参数seed是rand()的种子,用来初始化rand()的起始值。

可以认为rand()在每次被调用的时候,它会查看:
1) 如果用户在此之前调用过srand(seed),给seed指定了一个值,那么它会自动调用srand(seed)一次来初始化它的起始值。
2) 如果用户在此之前没有调用过srand(seed),它会自动调用srand(1)一次。
 
 
2. function:floor (向下取整)

c11: double floor (double x);

        floor floor (float x);

long double floor (long double x);

        doulbe floor (T x); //整型的附加重载;

与之对应的函数 ceil : 向上取整。

3. STL中resize(); 和 reserve();

reszie();

This function will %resize the %vector to the specified
* number of elements. If the number is smaller than the
* %vector's current size the %vector is truncated, otherwise
* the %vector is extended and new elements are populated with
* given data.
reserve();
This function attempts to reserve enough memory for the
* %vector to hold the specified number of elements. If the
* number requested is more than max_size(), length_error is
* thrown.
* The advantage of this function is that if optimal code is a
* necessity and the user can determine the number of elements
* that will be required, the user can reserve the memory in
* %advance, and thus prevent a possible reallocation of memory
* and copying of %vector data.

 

 

 

 
 
posted @ 2020-01-13 11:05  D_Q  阅读(142)  评论(0)    收藏  举报