当前位置:   article > 正文

C++中string类型insert方法用法集锦

C++中string类型insert方法用法集锦

C++方法的用法真的太多了,一个insert方法用法就多达8种,一不留神就用错来了,很神伤微笑

  1. // inserting into a string
  2. #include <iostream>
  3. #include <string>
  4. int main ()
  5. {
  6. std::string str="to be question";
  7. std::string str2="the ";
  8. std::string str3="or not to be";
  9. std::string::iterator it;
  10. // used in the same order as described above:
  11. str.insert(6,str2); // to be (the )question
  12. str.insert(6,str3,3,4); // to be (not )the question
  13. str.insert(10,"that is cool",8); // to be not (that is )the question
  14. str.insert(10,"to be "); // to be not (to be )that is the question
  15. str.insert(15,1,':'); // to be not to be(:) that is the question
  16. it = str.insert(str.begin()+5,','); // to be(,) not to be: that is the question
  17. str.insert (str.end(),3,'.'); // to be, not to be: that is the question(...)
  18. str.insert (it+2,str3.begin(),str3.begin()+3); // (or )
  19. std::cout << str << '\n';
  20. return 0;
  21. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/302696
推荐阅读
相关标签
  

闽ICP备14008679号