转自:http://hi.baidu.com/jrwen0/item/e7945407decabcd61ff046ca

#include <assert.h>    //设定插入点
#include <ctype.h>     //字符处理
#include <errno.h>     //定义错误码
#include <float.h>     //浮点数处理
#include <fstream.h>    //文件输入/输出
#include <iomanip.h>    //参数化输入/输出
#include <iostream.h>   //数据流输入/输出
#include <limits.h>    //定义各种数据类型最值常量
#include <locale.h>    //定义本地化函数
#include <math.h>     //定义数学函数
#include <stdio.h>     //定义输入/输出函数
#include <stdlib.h>    //定义杂项函数及内存分配函数
#include <string.h>    //字符串处理
#include <strstrea.h>   //基于数组的输入/输出
#include <time.h>     //定义关于时间的函数
#include <wchar.h>     //宽字符处理及输入/输出
#include <wctype.h>    //宽字符分类

string.h中的函数

@函数名称:     strdup
函数原型:     char *strdup(const char *s)
函数功能:     字符串拷贝,目的空间由该函数分配 
函数返回:     指向拷贝后的字符串指针
参数说明:     src-待拷贝的源字符串
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main()
{
    char *dup_str, *string="abcde";
    dup_str=strdup(string);
    printf("%s", dup_str);
    free(dup_str);
    return 0;
}

@函数名称:     strcpy
函数原型:     char* strcpy(char* str1,char* str2);
函数功能:     把str2指向的字符串拷贝到str1中去
函数返回:     返回str1,即指向str1的指针
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char string[10];
    char *str1="abcdefghi";
    strcpy(string,str1);
    printf("the string is:%s\n",string);
    return 0;
}

@函数名称:     strncpy
函数原型:     char *strncpy(char *dest, const char *src,int count)
函数功能:     将字符串src中的count个字符拷贝到字符串dest中去
函数返回:     指向dest的指针
参数说明:     dest-目的字符串,src-源字符串,count-拷贝的字符个数
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char string[10];
    char *str1="abcdefghi";
    strncpy(string,str1,3);
    string[3]='\0';
    printf("%s",string);
    return 0;
}

@函数名称:     strcat
函数原型:     char* strcat(char * str1,char * str2);
函数功能:     把字符串str2接到str1后面,str1最后的'\0'被取消
函数返回:     str1
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>

int main()
{
    char buffer[80];

strcpy(buffer,"Hello ");
    strcat(buffer,"world");
    printf("%s\n",buffer);
    return 0;
}

@函数名称:     strncat
函数原型:     char *strncat(char *dest, const char *src, size_t maxlen)
函数功能:     将字符串src中前maxlen个字符连接到dest中
函数返回:
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>

char buffer[80];

int main()
{
    strcpy(buffer,"Hello ");
    strncat(buffer,"world",8);
    printf("%s\n",buffer);
    strncat(buffer,"*************",4);
    printf("%s\n",buffer);
    return 0;
}

@函数名称:     strcmp
函数原型:     int strcmp(char * str1,char * str2);
函数功能:     比较两个字符串str1,str2.
函数返回:     str1<str2,返回负数; str1=str2,返回 0; str1>str2,返回正数. 
参数说明:
所属文件:     <string.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char *buf1="aaa", *buf2="bbb", *buf3="ccc";
    int ptr;
    ptr=strcmp(buf2, buf1);
    if(ptr>0)
      printf("buffer 2 is greater than buffer 1\n");
    else
      printf("buffer 2 is less than buffer 1\n");
    ptr=strcmp(buf2, buf3);
    if(ptr>0)
      printf("buffer 2 is greater than buffer 3\n");
    else
      printf("buffer 2 is less than buffer 3\n");
    return 0;
}

@函数名称:     strncmp
函数原型:     int strncmp(char *str1,char *str2,int count)
函数功能:     对str1和str2中的前count个字符按字典顺序比较
函数返回:     小于0:str1<str2,等于0:str1=str2,大于0:str1>str2
参数说明:     str1,str2-待比较的字符串,count-比较的长度
所属文件:     <string.h>

#include <string.h>
#include <stdio.h>
int main()
{
    int ptr;
    char *buf1="aaabbb",*buf2="bbbccc",*buf3="ccc";
    ptr=strncmp(buf2,buf1,3);
    if (ptr>0)
      printf("buffer 2 is greater than buffer 1");
    else
      printf("buffer 2 is less than buffer 1");
      ptr=strncmp(buf2,buf3,3);
    if (ptr>0)
      printf("buffer 2 is greater than buffer 3");
    else
      printf("buffer 2 is less than buffer 3");
    return(0);
}

@函数名称:     strpbrk
函数原型:     char *strpbrk(const char *s1, const char *s2)
函数功能:     得到s1中第一个“同时也出现在s2中”字符的位置指针
函数返回:     位置指针
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
char *p="Find all vowels";

while(p)
{
    printf("%s\n",p);
    p=strpbrk(p+1,"aeiouAEIOU");
}
return 0;
}

@函数名称:     strcspn
函数原型:     int strcspn(const char *s1, const char *s2)
函数功能:     统计s1中从头开始直到第一个“来自s2中的字符”出现的长度
函数返回:     长度
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>

int main()
{
    printf("%d\n",strcspn("abcbcadef","cba"));
    printf("%d\n",strcspn("xxxbcadef","cba"));
    printf("%d\n",strcspn("123456789","cba"));
    return 0;
}

@函数名称:     strspn
函数原型:     int strspn(const char *s1, const char *s2)
函数功能:     统计s1中从头开始直到第一个“不来自s2中的字符”出现的长度
函数返回:     位置指针
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main()
{
    printf("%d\n",strspn("out to lunch","aeiou"));
    printf("%d\n",strspn("out to lunch","xyz"));
    return 0;
}

@函数名称:     strchr
函数原型:     char* strchr(char* str,char ch);
函数功能:     找出str指向的字符串中第一次出现字符ch的位置
函数返回:     返回指向该位置的指针,如找不到,则返回空指针
参数说明:     str-待搜索的字符串,ch-查找的字符
所属文件:     <string.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char string[15];
    char *ptr, c='r';
    strcpy(string, "This is a string");
    ptr=strchr(string, c);
    if (ptr)
      printf("The character %c is at position: %d\n",c,ptr-string);
    else
      printf("The character was not found\n");
    return 0;
}

@函数名称:     strrchr
函数原型:     char *strrchr(const char *s, int c)
函数功能:     得到字符串s中最后一个含有c字符的位置指针
函数返回:     位置指针
参数说明:
所属文件:     <string.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char string[15];
    char *ptr,c='r';
    strcpy(string,"This is a string");
    ptr=strrchr(string,c);
    if (ptr)
      printf("The character %c is at position:%d",c,ptr-string);
    else
      printf("The character was not found");
    return 0;
}

@函数名称:     strstr
函数原型:     char* strstr(char* str1,char* str2);
函数功能:     找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)
函数返回:     返回该位置的指针,如找不到,返回空指针
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char *str1="Open Watcom C/C++",*str2="Watcom",*ptr;
    ptr=strstr(str1,str2);
    printf("The substring is:%s\n",ptr);
    return 0;
}

@函数名称:     strrev
函数原型:     char *strrev(char *s)
函数功能:     将字符串中的所有字符颠倒次序排列
函数返回:     指向s的指针 
参数说明:
所属文件:     <string.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char *forward="string";
    printf("Before strrev():%s",forward);
    strrev(forward);
    printf("After strrev(): %s",forward);
    return 0;
}

@函数名称:     strnset
函数原型:     char *strnset(char *s, int ch, size_t n)
函数功能:     将字符串s中前n个字符设置为ch的值
函数返回:     指向s的指针
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char *string="abcdefghijklmnopqrstuvwxyz";
    char letter='x';
    printf("string before strnset: %s",string);
    strnset(string,letter,13);
    printf("string after strnset: %s",string);
    return 0;
}

@函数名称:     strset
函数原型:     char *strset(char *s, int ch)
函数功能:     将字符串s中所有字符设置为ch的值
函数返回:     指向s的指针 
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char string[10]="123456789";
    char symbol='c';
    printf("Before strset(): %s", string);
    strset(string, symbol);
    printf("After strset(): %s", string);
    return 0;
}

@函数名称:     strtok
函数原型:     char *strtok(char *s1, const char *s2)
函数功能:     分解s1字符串为用特定分隔符分隔的多个字符串(一般用于将英文句分解为单词)
函数返回:     字符串s1中首次出现s2中的字符前的子字符串指针
参数说明:     s2一般设置为s1中的分隔字符
          规定进行子调用时(即分割s1的第二、三及后续子串)第一参数必须是NULL
          在每一次匹配成功后,将s1中分割出的子串位置替换为NULL(摘下链中第一个环),因此s1被破坏了
          函数会记忆指针位置以供下一次调用
        
所属文件:     <string.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char *p;
    char *buffer;
    char *delims={ " .," };

buffer=strdup("Find words, all of them.");
    printf("%s\n",buffer);
    p=strtok(buffer,delims);
    while(p!=NULL){
      printf("word: %s\n",p);
      p=strtok(NULL,delims);
    }
    printf("%s\n",buffer);
    return 0;
}

@函数名称:     strupr
函数原型:     char *strupr(char *s)
函数功能:     将字符串s中的字符变为大写
函数返回:
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char *string="abcdefghijklmnopqrstuvwxyz",*ptr;
    ptr=strupr(string);
    printf("%s",ptr);
    return 0;
}

@函数名称:     strlwr
函数原型:     char *strlwr(char *s)
函数功能:     将字符串中的字符变为小写字符
函数返回:     指向s的指针
参数说明:
所属文件:     <string.h>

#include<string.h>
int main()
{
    char str[]="HOW TO SAY?";
    printf("%s",strlwr(str));
    return 0;
}

@函数名称:     strlen
函数原型:     unsigned int strlen(char * str);
函数功能:     统计字符串str中字符的个数(不包括终止符'\0')
函数返回:     返回字符串的长度.
参数说明:
所属文件:     <string.h>

#include <stdio.h>
#include<string.h>
int main()
{
    char str[]="how are you!";
    printf("the lence is:%d\n",strlen(str));
    return 0;
}

@函数名称:     strerror
函数原型:     char *strerror(int errnum)
函数功能:     得到错误信息的内容信息
函数返回:     错误提示信息字符串指针
参数说明:     errnum-错误编号
所属文件:     <string.h>

#include <stdio.h>
#include <errno.h>
int main()
{
    char *buffer;
    buffer=strerror(errno);
    printf("Error: %s",buffer);
    return 0;
}

@函数名称:     memcpy
函数原型:     void *memcpy(void *dest, const void *src, size_t n)
函数功能:     字符串拷贝
函数返回:     指向dest的指针
参数说明:     src-源字符串,n-拷贝的最大长度
所属文件:     <string.h>,<mem.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char src[]="******************************";
    char dest[]="abcdefghijlkmnopqrstuvwxyz0123456709";
    char *ptr;
    printf("destination before memcpy:%s\n",dest);
    ptr=memcpy(dest,src,strlen(src));
    if (ptr)
      printf("destination after memcpy:%s\n",dest);
    else
      printf("memcpy failed");
    return 0;
}

@函数名称:     memccpy
函数原型:     void *memccpy(void *dest, const void *src, int c, size_t n)
函数功能:     字符串拷贝,到指定长度或遇到指定字符时停止拷贝
函数返回:
参数说明:     src-源字符串指针,c-中止拷贝检查字符,n-长度,dest-拷贝底目的字符串指针
所属文件:     <string.h>,<mem.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char *src="This is the source string";
    char dest[50];
    char *ptr;
    ptr=memccpy(dest,src,'c',strlen(src));
    if (ptr)
    {
      *ptr='\0';
      printf("The character was found:%s",dest);
    }
    else
      printf("The character wasn't found");
    return 0;
}

@函数名称:     memchr
函数原型:     void *memchr(const void *s, int c, size_t n)
函数功能:     在字符串中第开始n个字符中寻找某个字符c的位置
函数返回:     返回c的位置指针,返回NULL时表示未找到
参数说明:     s-要搜索的字符串,c-要寻找的字符,n-指定长度
所属文件:     <string.h>,<mem.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char str[17];
    char *ptr;
    strcpy(str,"This is a string");
    ptr=memchr(str,'r',strlen(str));
    if (ptr)
    printf("The character 'r' is at position: %d",ptr-str);
    else
    printf("The character was not found");
    return 0;
}

@函数名称:     memcmp
函数原型:     int memcmp(const void *s1, const void *s2,size_t n)
函数功能:     按字典顺序比较两个串s1和s2的前n个字节 
函数返回:     <0,=0,>0分别表示s1<,=,>s2
参数说明:     s1,s2-要比较的字符串,n-比较的长度
所属文件:     <string.h>,<mem.h>

#include <stdio.h>
#include <string.h>
int main() 

    char *buf1="ABCDE123"; 
    char *buf2="abcde456"; 
    int stat; 
    stat=memcmp(buf1,buf2,5); 
    printf("The strings to position 5 are "); 
    if(stat) printf("not "); 
    printf("the same\n"); 
    return 0; 
}

@函数名称:     memicmp
函数原型:     int memicmp(const void *s1, const void *s2, size_t n)
函数功能:     按字典顺序、不考虑字母大小写对字符串s1,s2前n个字符比较
函数返回:     <0,=0,>0分别表示s1<,=,>s2
参数说明:     s1,s2-要比较的字符串,n-比较的长度
所属文件:     <string.h>,<mem.h>

#include <stdio.h>
#include <string.h>
int main()
{
    char *buf1="ABCDE123";
    char *buf2="abcde456";
    int stat;
    stat=memicmp(buf1,buf2,5);
    printf("The strings to position 5 are ");
    if(stat) printf("not");
    printf("the same");
    return 0;
}

@函数名称:     memmove
函数原型:     void *memmove(void *dest, const void *src, size_t n)
函数功能:     字符串拷贝
函数返回:     指向dest的指针
参数说明:     src-源字符串,n-拷贝的最大长度
所属文件:     <string.h>,<mem.h>

#include <string.h>
#include <stdio.h>
int main()
{
    char dest[40]="abcdefghijklmnopqrstuvwxyz0123456789";
    printf("destination prior to memmove:%s\n",dest);
    memmove(dest+1,dest,35);
    printf("destination after memmove:%s",dest);
    return 0;
}

@函数名称:     memset
函数原型:     void *memset(void *s, int c, size_t n)
函数功能:     字符串中的n个字节内容设置为c
函数返回:
参数说明:     s-要设置的字符串,c-设置的内容,n-长度
所属文件:     <string.h>,<mem.h>

#include <string.h>
#include <stdio.h>
#include <mem.h>
int main()
{
    char buffer[]="Hello world";
    printf("Buffer before memset:%s\n",buffer);
    memset(buffer,'*',strlen(buffer)-1);
    printf("Buffer after memset:%s",buffer);
    return 0;
}

转载于:https://www.cnblogs.com/pamxy/archive/2013/03/05/2991511.html

c/c++头文件函数一览表相关推荐

  1. graphic头文件函数_graphics.h头文件

    graphics.h头文件是一款tc操作必备组件.graphics.h头文件主要是运行在win8.win7操作系统上,为用户提供了非常多函数类型,用户只需使用tc编译就可以使用这个软件,是用户进行tc ...

  2. graphic头文件函数_graphics.h头文件中文版

    graphics.h头文件中文版是一款tc操作运行必备组件,为用户提供非常丰富的图形函数,所有图形函数的原型均在graphics. h中,用户只需使用tc编译就可以使用graphics.h头文件中文版 ...

  3. algorithm头文件函数全集——史上最全,最贴心

    2022.4.8更: 随着本篇博客观看次数越来越多,假如有一点点疏忽,就可能造成更大的影响, 因此采取动态维护的策略: 从今天开始,每天我会检查评论区, 及时解答大家的疑问,修改可能存在的问题 如果哪 ...

  4. 简介明了——map+multimap头文件函数详解

    简介: 只需要记住这些: 1.map函数是一种映射,key–>value 2.map重载了[]运算符,所以可以直接使用 3.map中key值有序且去重(默认升序)   为了更方便.易懂, 笔者将 ...

  5. ctype.h(cctype) 头文件函数大全

    代码块里是笔者认为比较常用的函数,底部的附录是对cctype头文件中所有函数的归纳. 复制到编译器中观看最佳.觉得哪行不太懂直接取消注释运行就OK了. #include <iostream> ...

  6. string头文件函数用法大总结

    C++对应的头文件: #include <cstring> C对应的头文件: #include <string.h> 声明一个字符串变量 1)string s;//声明s字符串 ...

  7. c语言algorithm头文件,C++ algorithm头文件函数的基本用法

    algorithm /*algorithm头文件下的常用函数*/ /* 使用algorithm头文件,需要在头文件下加一行using namespace std;" */ //常用函数max ...

  8. graphic头文件函数_graphics.h头文件详解

    r getlinesettings(struct linesettingstype far *lineinfo); 该函数将有关线的信息存放到由lineinfo 指向的结构中, 表中linesetti ...

  9. string头文件函数

    1.strlen() 原型:extern int strlen(char *s) 用法:#include<string.h> 功能:计算字符串的长度 说明:返回s的长度,不包括结束符NUL ...

最新文章

  1. 简易在线实验室管理系统
  2. 【深度学习】我用 PyTorch 复现了 LeNet-5 神经网络(MNIST 手写数据集篇)!
  3. apache URL重写
  4. 【转载】输出二进制 C
  5. 负载均衡集群HAProxy安装篇
  6. 外媒:美国政府官员建议阻止英飞凌收购赛普拉斯
  7. oracle ns,RAC到单实例SWITCHOVER
  8. 判断浏览器是否支持websocket的方法
  9. 我来到这世上,却不曾歌唱
  10. 登陆服务器老出现“达到最大连接数解决方法
  11. 打印菱形 java_怎么用java打印菱形?
  12. 《一天搞懂深度学习》下载
  13. 车联网群雄逐鹿,通信业将如何掘金?
  14. 联想拯救者笔记本电脑亮度无法调节解决办法
  15. ES使用Ngram分词器实现wildcard高性能替代方案
  16. GitHub使用教程详细图解
  17. matlab图像合成实例,MATLAB图像合成及其实现
  18. MAXENT模型的生物多样性生境模拟与保护优先区甄选、自然保护区布局优化评估及论文写作技巧
  19. Hive基础知识概念
  20. 「需求广场」需求词更新明细(七)

热门文章

  1. Istio究竟是干嘛的?
  2. 一次彻底搞透协议设计(没做过通讯底层也没有关系)!
  3. 多线程:happens-before原则
  4. Java:假设车库有3个车位(可以通过boolean[]数组来表示车库)可以停车,写一个程序模拟多个用户开车离开,停车入库的效果。注意:车位有车时不能停车。
  5. jQuery面试题-区别mouseover和mouseenter的不同之处(看了也许对你有好处)
  6. shell命令 vxworks5.5_vxWorks shell命令
  7. pb retrieve时停止工作_电机没有抱闸如何利用变频器实现减速停止
  8. java中大数开方_Java中的大数运算
  9. 统计123出现次数_如何使用 count 统计词条出现次数?
  10. Anaconda:成功解决Anaconda下载时速度超慢(conda下载慢)的几种方法图文教程