zoukankan      html  css  js  c++  java
  • 一个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/

  • 相关阅读:
    使用高精度计算斐波那契数列 c++
    纪中9日T4 2298. 异或
    洛谷 P1416 攻击火星
    线段树小结
    纪中5日T3 1566. 幸运锁(lucky.pas/c/cpp)
    Title
    Title
    Title
    Title
    Title
  • 原文地址:https://www.cnblogs.com/xkxf/p/12839819.html
Copyright © 2011-2022 走看看