The first week of learning C++

C ++ string class
1 beginning
'


``
(1)#include<iostream>
#include<string>(可不写)
using namespace std;
(2)#include<bits/stdc++.h>
using namespace std;

2. Input
(1) string s;
cin>>s; ( note that cin stops when it encounters a space when reading a string )
(2) string s;
getline(cin,s);
(3) char s[105] ;
cin.get(s,105);
(4)char s[105];
cin.getline(s,105);
(note that the (3) and (4) input methods will remove and delete the newline characters, which will not affect the next time Read)

3.输出
cout<<s<<endl;

4. Find the length of the string
(1)s.length()
(2)s.size()
5. Find the substring
(1)s.find(s1)
(2)s.rfind(s1) (second Search)
(The result is the position of the search string)

6. Return substring function: substr();
delete character: erase();
replace character: replace();

7. Insert function
Insert picture description here
8. Constructor
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_54489097/article/details/112735955