天天看點

C++字元串的插入與删除C++字元串的插入與删除

C++字元串的插入與删除

字元串的插入是指在字元串中指定的位置插入指定的字元串。

字元串删除是指在字元串中指定的位置删除指定長度個字元。

include <stdio.h>

int main(int argc,const char* argv[])
{

	std::string str1 = "Hedl";
	std::string str2 = "llo Worl";

	//以下是在字元串str1的第2個位置插入字元串str2的所有内容。
	std::cout << str1.insert(2,str2) <<std:: endl;

	//以下字元串str1的第二個字元開始,連續删除8個字元
	std::cout << str1.erase(2,8) <<std::endl;

	return 0;
}
           

繼續閱讀