首页 > 编程语言 > 详细

C++之string学习

时间:2018-09-19 23:20:23      阅读:204      评论:0      收藏:0      [点我收藏+]

 

 

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

 

C++之string学习

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!