string insert()函数的用法

来源:互联网 发布:ppt图表无法修改数据 编辑:程序博客网 时间:2024/06/05 00:13


#include <iostream>#include <string>int main (){  std::string str="to be question";  std::string str2="the ";  std::string str3="or not to be";  std::string::iterator it;  // used in the same order as described above:  str.insert(6,str2);                 // to be (the )question  str.insert(6,str3,3,4);             // to be (not )the question  str.insert(10,"that is cool",8);    // to be not (that is )the question  str.insert(10,"to be ");            // to be not (to be )that is the question  str.insert(15,1,':');               //加一个'.' to be not to be(:) that is the question  it = str.insert(str.begin()+5,','); // to be(,) not to be: that is the question  str.insert (str.end(),3,'.');       // to be, not to be: that is the question(...)  str.insert (it+2,str3.begin(),str3.begin()+3); // (or )  std::cout << str << '\n';  return 0;}//output  to be, or not to be: that is the question...


毕竟官方用例,hin nice


link:
http://www.cplusplus.com/reference/string/string/insert/




0 0