string 操作

jacyOler / 2023-08-16 / 原文

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     ios::sync_with_stdio(false);
 5     string s1="what about to ask ",s2="Mike telephone number";
 6     //1
 7     s1.replace(11,16,"asking");
 8     cout<<s1<<endl;
 9     
10     //2
11     s2=s2.insert(5,"for ");
12     cout<<s2<<endl;
13     
14     //3
15     string s=s1+s2;
16     cout<<s<<endl;
17     
18     //4
19     if(s2.find("Mike")!=s2.npos){
20         cout<<true<<endl;
21     }
22     else{
23         cout<<false<<endl;
24     }
25     
26     if(s.find("Mike")!=s.npos){
27         cout<<true<<endl;
28     }
29     else{
30         cout<<false<<endl;
31     }
32     
33     //5
34     if(s2.find("z")!=s2.npos){
35         cout<<true<<endl;
36     }
37     else{
38         cout<<false<<endl;
39     }
40     
41     return 0;
42 }