C++ replace()函数返回string 能放的最大元素个数。(不同于capacity)
size _ type max _ size( ) const; basic_string
= s.capacity ( ); max = s.max_size ( ); // max=4294967294.
basic_string::rfind 寻找给定的string。返回找到的第一个string 下标值;如果没找到
则返回npos。
与find 不同的是:rfind 默认从npos 开始找。其他相同。
basic_string::replace 将原string 中的元素或子串替换。返回替换后的string。
#include
#include
using namespace std;int main()
{
string str1("String handling C++ style.");
string str2("STL Power");cout << "Initial strings:n";
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << "nn";// demonstrate replace
cout << "Replace 8 characters in str1 with str2:n";
str1.replace(7, 8, str2);
cout << str1 << endl;return 0;
}/*
Initial strings:
str1: String handling C++ style.
str2: STL PowerReplace 8 characters in str1 with str2:
String STL Power C++ style.*/
指定具体位置#include
using std::cout;
using std::endl;#include
using std::string;int main()
{
string string1( "abc edfgh ijk lmno pqr stu vw xyz" );
cout << "Original string:n" << string1 << endl << endl;int position = string1.find( "." ); // find first period
while ( position != string::npos )
{
string1.replace( position, 2, "12345;;123", 5, 2 );
position = string1.find( ".", position + 1 );
}cout << string1 << endl;
return 0;
}/*
Original string:
abc edfgh ijk lmno pqr stu vw xyzabc edfgh ijk lmno pqr stu vw xyz
*/
insert(), erase(), and replace().#include
#include
using namespace std;
int main()
{
string str1("A");
string str2("B");
cout << "Initial strings:n";
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << "nn";
str1.insert(6, str2);
cout << str1 << "nn";
str1.erase(6, 9);
cout << str1 <<"nn";
str1.replace(7, 8, str2);
cout << str1 << endl;
return 0;
}
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔