assign()_百度百科

assign()_百度百科

    assign()
      C++ string类的成员函数,用于拷贝、赋值操作,它们允许我们顺次地把一个string 对象的
      部分内容拷贝到另一个string 对象上。
      函数原型:
      string &operator=(const string &s);把字符串s赋给当前字符串
      string &assign(const char *s);用c类型字符串s赋值
      string &assign(const char *s,int n);用c字符串s开始的n个字符赋值
      string &assign(const string &s);把字符串s赋给当前字符串
      string &assign(int n,char c);用n个字符c赋值给当前字符串
      string &assign(const string &s,int start,int n);把字符串s中从start开始的n个字符赋给当前字符串
      string &assign(const_iterator first,const_itertor last);把first和last迭代器之间的部分赋给字符串
      函数以下列方式赋值:
      用str为字符串赋值,
      用str的开始num个字符为字符串赋值,
      用str的子串为字符串赋值,子串以index索引开始,长度为len
      用num个字符ch为字符串赋值.
      例如以下代码:
      1、string s1( "Mississippi" ); string s3;
      // 拷贝s1 的前4 个字符
      s3.assign( s1, 0, 4 );
      s3 现在的值为“Miss”。
      2、 string str1, str2 = "War and Peace";
      str1.assign( str2, 4, 3 );
      cout << str1 << endl;
      显示
      and

原文链接: https://www.cnblogs.com/lexus/archive/2013/01/01/2841452.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    assign()_百度百科

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/74262

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午4:19
下一篇 2023年2月9日 下午4:19

相关推荐