码迷,mamicode.com
首页 > 编程语言 > 详细

c++ string assign =

时间:2014-07-09 23:22:50      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:http   art   代码   c++   htm   div   

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;

 

c++ string assign =,布布扣,bubuko.com

c++ string assign =

标签:http   art   代码   c++   htm   div   

原文地址:http://www.cnblogs.com/porter/p/3829700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!