zoukankan      html  css  js  c++  java
  • C++ string用法

    #include <iostream>
    #include <string>
    // using string constructors
    
    int main()
    {
        using namespace std;
        string one("Lottery Winner!");     
        cout << one << endl;               // 
        string two(20, '$');               // two初始化为由20个字符串组成
        cout << two << endl;
        string three(one);                 // 
        cout << three << endl;
        one += " Oops!";                   // overloaded +=
        cout << one << endl;
        two = "Sorry! That was ";
        three[0] = 'P';
        string four;                       // ctor #4
        four = two + three;                // overloaded +, =
        cout << four << endl;
        char alls[] = "All's well that ends well";
        string five(alls,20);              // 输出前20个字符
        cout << five << "!
    ";
        string six(alls+6, alls + 10);  // 数组名相当于指针,指向第一个元素地址,等同于six(alls,6,10)
        cout << six  << ", ";//输出第7和第11地址之间的元素
        string seven(&five[6], &five[10]); //等同于seven(alls+6, alls + 10)
        cout << seven << "...
    ";
        string eight(four, 7, 16);         // ctor #7
        cout << eight << " in motion!" << endl;
        // std::cin.get();
        return 0; 
    }

  • 相关阅读:
    颓废ing
    Linux下PF_PACKET的使用(todo)
    TIPC协议(todo)
    TOP命令详解(todo)
    so查找顺序
    把lib打包到so中
    -Bsymbolic: 优先使用本地符号
    GitHub 上最火的 Python 开源项目zz
    __attribute__((weak)) zz
    kmalloc(zz)
  • 原文地址:https://www.cnblogs.com/hsy1941/p/10127220.html
Copyright © 2011-2022 走看看