zoukankan      html  css  js  c++  java
  • c++ string操作

    #include <iostream>
    #include <string>

    using namespace std;


    int main()
    {
      string str1("hello");
      string str2(" study c++");

      string::iterator str_iter = str1.begin();
      str1.insert(str_iter,'a');
      cout << str1 << endl;

      str1.insert(str_iter,3,'b');
      cout << str1<< endl;

      string::iterator str1_iter1 = str1.begin();
      string::iterator str2_iter1 = str2.begin();
      string::iterator str2_iter2 = str2.end();
      
      str1.insert(str1_iter1,str2_iter1,str2_iter2);
      cout << str1 << endl;

      str1 = "hello";
      str1.assign(str2);
      cout << str1 << endl;

      str1.assign(8,'K');
      cout << str1 << endl;

      str1 = "abcdef";
      cout << str1 << endl;
      string::iterator str1_iter2 = str1.begin();
      str1_iter2++;
      str1.erase(str1_iter2);
      cout << str1<< endl;
      
      string::iterator str1_iter3 = str1.end();
      str1_iter3--;
      str1_iter2++;
      str1_iter2++;

      str1.erase(str1_iter2,str1_iter3);
      cout << str1 << endl;

      str1.insert(0, 3, 'K');
      cout << str1 << endl;

      str1 = "hello";
      str1.insert(5, str2);
      cout << str1 << endl;

      system("pause");
      return 0;
    }

    =================================================

    ahello
    bbbahello
    study c++bbbahello
    study c++
    KKKKKKKK
    abcdef
    acdef
    acdf
    KKKacdf
    hello study c++
    请按任意键继续. . .

  • 相关阅读:
    Oracle 10g AND Oracle 11g手工建库案例--Oracle 11g
    第十七篇:实例分析(1)--初探WDDM驱动学习笔记(八)
    Git权威指南学习笔记(二)Git暂存区
    C++11多线程教学II
    c++ 11 多线程教学(1)
    C++11 多线程 基础
    C++11下的线程池以及灵活的functional + bind + lamda
    intel线程库tbb的使用
    TBB入门
    TTB 基本
  • 原文地址:https://www.cnblogs.com/herd/p/10994597.html
Copyright © 2011-2022 走看看