福州专业网站制作的公司,设置网站建设方案,随州网站,wordpress 站外 链接C-串以一个全0字节结束字符序列#xff0c;C-串的空间长度为字符串长度加1。 char buffer[7]”hello!”#xff1b;注意是7而非6#xff1b;
C-串的类型为char*#xff0c;也就是const char*。Char*称为字符指针#xff0c;表示C-串的起始地址。
如;
char *strHe…
C-串以一个全0字节结束字符序列C-串的空间长度为字符串长度加1。 char buffer[7]”hello!”注意是7而非6
C-串的类型为char*也就是const char*。Char*称为字符指针表示C-串的起始地址。
如;
char *strHello;
cout*strendl; //显示H
coutstrendl; //显示Hello //
//C-串操作
//
#includeiostream #includecstring using namespace std; int main() { char *s1Hello,world_; char *s21234_; char a[20]; coutstrcpy(a,s1)endl; //复制 cout(strcmp(a,s1)0 ? : not)enqual\n; //比较 coutstrcat(a, s2)endl; //连接 coutstrrev(a)endl; //倒置 coutstrset(a,c)endl; //设置 cout(strstr(s1, ell) ? : not )found\n; //查找串 cout(strchr(s1,c) ? : not )found\n; //查找字符 } String是一种自定义类型比C-串更方便自动处理空间占用问题有搜索操作插入操作取长度删除字符删除字串判断空串。
//
//string操作
//
#includeiostream #includealgorithm using namespace std; int main() { string a,s1Hello,world_; string s21234_; as1; coutaendl; //复制 cout(as1 ? : not)equal\n; //比较 coutas2endl; //连接 reverse(a.begin(), a.end()); coutaendl; //倒置串 couta.replace(0,9,9,c)endl; //设置 cout(s1.find(ell)!-1 ? : not)found\n;//查找串 cout(s1.find(c)! -1 ? :not)found\n; //查找字符 }