zoukankan      html  css  js  c++  java
  • C++之string学习

    #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
    ",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("相等
    ");
        }
    
        string t5 = "Liming is doing homework";
        int num1 = t5.rfind("i");
    
        system("pause");
        return 0;
    }
  • 相关阅读:
    Hibernate的检索
    Java 多线程
    可信软件开发
    Linux复习3
    Linux复习2
    Linux复习1
    使用Sourcetree(for windows)建立github同步仓库
    Session技术
    Cookie技术
    Ajax技术
  • 原文地址:https://www.cnblogs.com/weiyouqing/p/9678136.html
Copyright © 2011-2022 走看看