C++常用头文件

C++常用头文件,第1张

C++常用头文件 标准C++头文件

using namespace std;

1. #include

算法类函数

函数作用void sort (RandomAccessIterator first, RandomAccessIterator last)默认升序void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp)comp为自定义排序规则
#include 
#include 
using namespace std;
int main ()
{
  //定义一个大小为10的数组
  int arr[10] = {3, 5, 8, 2, 0, 9, 4, 7, 1, 6};
  //对数组前5个元素进行排序
  sort(arr, arr+5);
  for(int i=0; i < 10; i++)
  {
      printf("%d ", arr[i]);
  }
  return 0;
}

执行结果:0 2 3 5 8 9 4 7 1 6

#include 
#include 
using namespace std;
bool comp(int x, int y)
{
    // 按升序进行排序
    return x < y;
    // 按降序进行排序
    //return x > y;
}
int main ()
{
  //定义一个大小为10的数组
  int arr[10] = {3, 5, 8, 2, 0, 9, 4, 7, 1, 6};
  //对数组前5个元素进行排序
  sort(arr, arr+5, comp);
  for(int i=0; i < 10; i++)
  {
      printf("%d ", arr[i]);
  }
  return 0;
}

执行结果:0 2 3 5 8 9 4 7 1 6

2. #include

定义数据流输入输出

函数作用cin>>数据输入流cout<<数据输出流 3. #include

头文件cstdio/stdio.h是C/C++使用最频繁的文件,因为文件中包含很多常用的方法

函数作用scanf( ) / printf( )格式化输入输出getchar( ) / putchar( )输入/输出一个字符gets( ) / puts( )输入/输出一个字符串FILE* fopen( ) / fclose( )文件访问
#include 
int main ()
{
  FILE * pFile;
  pFile = fopen ("myfile.txt","w");
  if (pFile!=NULL)
  {
    fputs ("fopen example",pFile);
    fclose (pFile);
  }
  return 0;
4. #include

数学函数

函数作用int abs(int i)返回整型参数i的绝对值double exp(double x)返回指数ex的值double log(double x)返回对数logex的值double log10(double x)返回log10x的值double pow(double x,double y)返回xy的值double pow10(int p)返回10p的值double sqrt(double x)返回+√x的值double ceil(double x)返回不小于x的最小整数double floor(double x)返回不大于x的最大整数void srand(unsigned seed)初始化随机数发生器int rand( )产生一个随机数并返回这个数double acos(double x)返回x的反余弦cos-1(x)值,x为弧度double asin(double x)返回x的反正弦sin-1(x)值,x为弧度double atan(double x)返回x的反正切tan-1(x)值,x为弧度double cos(double x)返回x的余弦cos(x)值,x为弧度double sin(double x)返回x的正弦sin(x)值,x为弧度double tan(double x)返回x的正切tan(x)值,x为弧度 5. #include

字符处理

函数作用isalpha()判断一个字符是否为字母, 如果是字母则返回非零, 否则返回0islower()判断一个字符是否是小写字母,如果是小写字母则返回非零, 否则返回0isupper()判断一个字符是否是大写字母,如果是大写字母则返回非零, 否则返回0isalnum()判断一个字符是否为数字或字母,如果是则返回非零, 否则返回0isblank(space和t)判断字符是否为空格或制表符isspace(space、t、r、n)/tolower()将大写字母转换为小写字母toupper()将小写字母转换为大写字母 6. #include

字符串处理

7. #include

STL位集容器

8. #include

STL线性表容器

9. #include

STL动态数组容器

10. #include

STL映射容器

11. #include

STL队列容器

12. #include

STL集合容器

13. #include

STL堆栈容器

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5715050.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存