常用库函数

it2024-05-09  48

replace()用法  #include<iostream> #include<string> using namespace std; int main() { string str = "abcdef"; str.replace(0,3,"XXX"); cout << str << endl; //输出: XXXdef str.replace(0, 3, 3, 'Y'); cout << str << endl; //输出: YYYdef string s = "2020"; str.replace(0, 3, s, 0, 3); cout << str << endl; //输出: 202def return 0; }

 

最新回复(0)