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比较