一些函数的使用

243 阅读1分钟

1.strcmp

使用格式:类型 strcmp(参数1,参数2)

功 能: 比较参数1和参数2(1、若参数1>参数2,返回正数;2、若参数1<参数2,返回负数;3、若参数1=参数2,返回0;)

用来判断两字符串是否相等

例子

#include <cstring>

char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "aaa";
if(strcmp(buf1,buf3) == 0)
cout<<"equal" ;

2.lower_bound

头文件:algorithm

使用格式 : iterator lower_bound(iterator t1, iterator t2, val);

对象:有序数组或容器

如果搜寻目标是 set容器: iterator lower_bound(val);

功 能: lower_bound()返回值是一个迭代器,返回指向 大于等于 key的第一个值的位置.

例子

include <algorithm>

int pos = lower_bound(A.begin() , A.end() , 6)-A.begin();

pow

使用格式: double pow( double x, double y );

功 能: 计算x的y次幂

所属文件: <math.h>