C++之string学习

2021-06-22 14:06

阅读:622

标签:use   min   int   system   添加   \n   字符   学习   string   

 

 

#define  _CRT_SECURE_NO_WARNINGS
#include 
#include 

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

 

C++之string学习

标签:use   min   int   system   添加   \n   字符   学习   string   

原文地址:https://www.cnblogs.com/weiyouqing/p/9678136.html


评论


亲,登录后才可以留言!