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; 
    }

  • 相关阅读:
    方法参数的传递方式
    方法设计
    接口
    SQL 安装MySQL
    Windows 10 安装 wordpress
    Windows10安装PHP7+Apache 2.4
    做一个增删改查的工程
    清除缓存
    创建POJO
    VI快捷键
  • 原文地址:https://www.cnblogs.com/hsy1941/p/10127220.html
Copyright © 2011-2022 走看看