replace()
替换字符串的指定部分
#include <iostream>
#include <string>
int main()
{
std::string str("The quick brown fox jumps over the lazy dog.");
//替换[10,10+5)的内容
str.replace(10, 5, "red"); // (5)
str.replace(str.begin(), str.begin() + 3, 1, 'A'); // (6)
std::cout << str << '\n';
return 0;
}
substr()
返回字串
#include <string>
#include <iostream>
using namespace std;
int main(){
string s{"0123456789abcdefg"};
string sub1 = s.substr(10);//[10,size())
string sub2 = s.substr(5,3);//[5,5+3)
}
copy()
复制字符
#include <string>
#include <iostream>
using namespace std;
int main()
{
string foo("quuuux");
char bar[7]{};
foo.copy(bar, sizeof(bar));
cout << bar << '\n';
}