一个FLAG #23# cstring(2)

例子

使用C语言的字符串库,更多请看参考1

#include <cstdio>
#include <cstring>
int main()
{     
    // NOTICE 在处理字符串时,如果越界,通常在编译时并不报错。
    // 但是运行时会有未定义的行为。
    // 因此要确保字符数组长度大于其存储的字符串长度。
    
    // ######## 1 STRCPY ######### 
    
    // strcpy = string copy
    // 将其作为赋值号使用
    char s1[10] = "hello C
", s2[10];
    printf(strcpy(s2, s1)); // => hello C
    printf(s2); // => hello C
    
    
    // ######## 2 STELEN #########
    
    // strlen = string length
    
    // ######## 3 STRCAT #########
    
    // strcat = string concatenate 或者 string catenate 
    char s3[32] = "head jjjjjjjjj", s4[] = " tail
";
    printf(strcat(s3, s4)); // => head jjjjjjjjj tail
    printf(s3); // => head jjjjjjjjj tail
    
    // ######## 4 STRCMP #########
    // 总之可以测试两字符串间任何可能的关系
     
    return 0;
}

参考

[1] http://www.cplusplus.com/reference/cstring/

原文地址:https://www.cnblogs.com/xkxf/p/12839819.html