String内部函数-用于处理字符串

来源:互联网 发布:域名申请. 编辑:程序博客网 时间:2024/05/19 08:00

index 翻译-> 索引;
c和c++的index均由0开始,并非惯性思维的1;

index 函数

#include <string.h>main(){    char *s = "0123456789012345678901234567890";// 定义字符指针    char *p;    p = index(s, '5');//index 函数查找s中‘5’,并返回其地址    printf("%s\n", p);}
//append追加函数string str1("Welcome")str1.append(" to come")//cout: "Welcome to come"str1.append(" to come",3,2)//cout:" Welcome c"// 3等价于index, n等价于2
//assgin 赋值函数string str1="world";str.assgin("hello");//cout:"hello"
//at(index) 返回index当前字符string str1="hello";str1.at(2); //retrun ‘l’
//clean 函数string str2=“hello”;str2.clean() //清除当前字符串
//erase(index,n) string str1="welcome"str1.erase(2,3)//cout:'weme'
//empty() 判断字符串是否为空string str1="welcome"str1.empty()// return 1;
//compare 比较两个字符串str1.compare(str2) //str1与str2比较 
0 0
原创粉丝点击