strlen(str) 求串长
串类型的最小操作子集
substr
求子串的函数
#include<string>
#include<iostream>
using namespace std;
main()
{
string s("12345asdf");
string a=s.substr(0,5); //获得字符串s中 从第0位开始的长度为5的字符串//默认时的长度为从开始位置到尾
cout<<a<<endl;
}
输出结果为
12345
strcmp
比较两个字符串的大小,返回比较结果
用法i=strcmp(str1,str2);
①字符串1小于字符串2,strcmp函数返回一个负值;
②字符串1等于字符串2,strcmp函数返回零;
③字符串1大于字符串2,strcmp函数返回一个正值;
strcpy
用于实现两个字符串的拷贝
strcpy(str1,str2);
把字符串2的内容完全复制到字符串1中(字符串1必须是字符串变量)