string (1)
string& append (const string& str);
substring (2)
string& append (const string& str, size_t subpos, size_t sublen);
c-string (3)
string& append (const char* s);
buffer (4)
string& append (const char* s, size_t n);
fill (5)
string& append (size_t n, char c);
range (6)
template <class InputIterator>
string& append (InputIterator first, InputIterator last);
initializer list(7)
string& append (initializer_list<char> il);

using namespace std;
int main()
{
string s1 = "abc";
string s2 = "def";
s1.append(s2);
cout << "1 " << s1 << endl;
string s3 = "ghi";
try{
s1.append(s3, 4, 3);
}catch(out_of_range){
cout << "out_of_range" << endl;
}
cout << "2 " << s1 << endl;
const char *s4 = "hello";
s1.append(s4);
cout << s1 << endl;
const char *s5 = "weather";
s1.append(s5, 3);
cout << s1 << endl;
s1.append(5, '$');
cout << s1 << endl;
string s6 = "12345";
s1.append(s6.begin() + 1, s6.end() - 2);
cout << s1 << endl;
initializer_list<char> s7 = {'q', 'w', 'e', 'r'};
s1.append(s7);
cout << s1 << endl;
return 0;
}

string::append的更多相关文章

  1. C++ string append方法的常用用法

    append函数是向string的后面追加字符或字符串. 1).向string的后面加C-string string s = “hello “; const char *c = “out here “ ...

  2. C++ string append()添加文本

    C++ string append()添加文本 1.  C++ string append()添加文本 使用append()添加文本常用方法: 直接添加另一个完整的字符串: 如str1.append( ...

  3. std::string::append函数

    string& append (const string& str); string& append (const string& str, size_t subpos ...

  4. 为什么operator>>(istream&, string&)能够安全地读入长度未知的字符串?

    一般而言,实现"读入用户输入的字符串",程序中自然不能对用户输入的长度有所限定.这在C++中很容易实现,而在C中确没那么容易. 这一疑问,我在刚学C++的时候也在脑中闪现过:不过很 ...

  5. 标准C++中的string类的用法总结

    标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...

  6. How to: Convert Between Various String Types

      This topic demonstrates how to convert various Visual C++ string types into other strings. The str ...

  7. c++:string函数

    string类的构造函数:string(const char *s);    //用c字符串s初始化string(int n,char c);     //用n个字符c初始化此外,string类还支持 ...

  8. C++中string,wstring,CString的基本概念和用法

    一.概念 string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中.wstring是操作宽字符串的类.C++标准程序库对于string的设 ...

  9. C++ STL string

    要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...

随机推荐

  1. python安装第三方库报错:Cannot uninstall '***'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

    pip install --ignore-installed ${PACKAGE_NAME}

  2. 【VS开发】修改窗口背景颜色大全

    如何修改frame窗口的背景颜色?  MDI窗口的客户区是由frame窗口拥有的另一个窗口覆盖的.为了改变frame窗口背景的颜色,只需要这个客户区的背景颜色就可以了.你必须自己处理WM_ERASEB ...

  3. 如何在picture上显示透明Label

  4. Windows 下部署 hadoop spark环境

    一.先在本地安装jdk 我这里安装的jdk1.8,具体的安装过程这里不作赘述 二.部署安装maven 下载maven安装包,并解压 设置环境变量,MAVEN_HOME=D:\SoftWare\Mave ...

  5. Maximum Frequency Stack

    Implement FreqStack, a class which simulates the operation of a stack-like data structure. FreqStack ...

  6. 【转帖】刘备三顾茅庐,请Elasticsearch出山

    刘备三顾茅庐,请Elasticsearch出山 2019-08-08 18:31 https://www.sohu.com/a/332454886_463994?spm=smpc.author.fd- ...

  7. python -- TypeError: 'module' object is not callable

    文件: 代码: import pprintmessge = 'It was a bringht cold day in April,and the clocks were striking thrir ...

  8. # G++出现cannot open output file … : Permission denied问题

    G++出现cannot open output file - : Permission denied问题 这是因为之前的编译运行程序没有退出,导致下一次编译运行无法进行,这应该是命令行下运行才可能出现 ...

  9. Codeforces 1189D2. Add on a Tree: Revolution

    传送门 首先可以证明一颗树合法的充分必要条件是不存在某个节点的度数为 $2$ 首先它是必要的,考虑任意一条边连接的两点如果存在某一点 $x$ 度数为 $2$ ,那么说明 $x$ 还有连一条边出去,那么 ...

  10. tensorflow零起点快速入门(3)

    创造并运行数据 创造了-3到3的32条数据,然后通过sess.run获取并显示输出数据. x=tf.linspace(-3.0,3.0,32) print(x) sess=tf.Session() r ...