📄 chapter2-19.cpp
字号:
//文件名:CHAPTER2-19.cpp
#include <string>
#include <iostream>
using namespace std ;
void main()
{
string str1("012"); //给字符串str1赋值
string str2("345"); //给字符串str2赋值
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
str1.append(str2); //把字符串str2增加打str1的尾部
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
str2 = "567"; //重新对str2赋值
// 把str2的部分元素插入到str1的尾部,从str2的第一个元素开始,插入的元素长度为2
str1.append(str2, 1, 2);
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
char achTest[] = {'8', '9', 'A'};
str1.append(achTest, 2); //把字符组中的前两个元素插入到str1的尾部
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
// append all of a string literal to str1
char szTest[] = "ABC";//定义了一个字符组
str1.append(szTest); //把字符组中的所有元素插入到str1的尾部
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
str1.append(1, 'D'); //把单个字符插入到str1的尾部
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
// append str2 to str1 using iterators
str2 = "EF";
str1.append (str2.begin(), str2.end());//使用迭待器把str2插入到str1的尾部
cout << "str1 = " << str1.c_str() << endl; //把str1打印出来
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -