【C++基础】C-串知识整理

【C-串比较的错误方式】不能直接比较

char buffer1[6]="hello";
char buffer2[6]="hello";
cout<<(buffer1==buffer2?"":"not")<<"equal
";

【C-串的各种操作】

#include<iostream>
#include<string.h>//C-串操作的头文件
using namespace std;

int main()
{
    char* s1="hello ";
    char* s2="123";
    char a[20];

    strcpy(a,s1);                                   //复制
    cout<<(strcmp(a,s1)==0?"":" not")<<"equal
";   //比较
    cout<<strcat(a,s2)<<endl;                       //连接
    cout<<strrev(a)<<endl;                          //倒置
    cout<<strset(a,'c')<<endl;                            //设置
    cout<<(strstr(s1,"ell")?"":"not ")<<"found
";  //查找串
    cout<<(strchr(s1,'c')?"":"not ")<<"found
";    //查找字符

    return 0;
}
原文地址:https://www.cnblogs.com/jixiaowu/p/3914176.html