#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>

#include <string>

using namespace std;

int main(int argc, char * argv[])
{
    //string str2 = "xiaoliang";
    //string str3("xiaohei", 5);
    //string str4;
    //string str5 = "";

    string str("xiaohong");

    str.append("love");
    str.append("youddddd",3);//只取前三个字符
    str.append("overy",1,4); //从offset =1 开始连续添加四个字符;
    str.append(2,' ');//添加两个空格

    const char * cstr = str.c_str(); //

    printf("%s\n",cstr);

    //考虑效率问题
    string t1;
    t1.resize(1024);
    t1.clear();

    t1.append("wei ");
    t1.append("you ");
    t1.append("qing");

    string t2 = "hello";
    t2[1] = 'E';
    t2.at(2) = 'L';

    string t4 = "yes";
    if (t4 == "yes")
    {
        printf("相等\n");
    }

    string t5 = "Liming is doing homework";
    int num1 = t5.rfind("i");

    system("pause");
    return 0;
}

 

相关文章:

  • 2021-07-31
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2019-09-04
  • 2021-09-19
  • 2022-01-18
猜你喜欢
  • 2021-08-30
  • 2022-12-23
  • 2022-02-23
  • 2022-02-19
  • 2021-04-17
  • 2021-12-09
  • 2021-08-08
相关资源
相似解决方案