基本定义
string 字符串名;
初始化
string 字符串名 = "赋值内容";
基本输入
1、不带空格输入 cin >> 字符串名;
2、带空格输入 getline(cin,字符串名);
基本输出
cout << 字符串 ;
基本函数
1、+ += > < == != >= <=
2、求string的长度 字符串名.size();
删除子串
string s1 = "Real Steel";
s1.erase(1, 3); //删除从位置1开始后面的3个字符,此后 s1 = "R Steel"
插入子串
string s1 = "Limitless", s2="00";
s1.insert(2, "123"); //在下标 2 处插入字符串"123",s1 = "Li123mitless"
查找子串
string s1 = "apple people";
s1.find("ple"); //查找 "ple" 出现的位置 返回值为子串第一次出现的下标返回值为2
s1.find("ple",5); //从下标为5的地方查找"ple"的位置,返回值为9
s1.find("orange"); //查找"orange"的位置,没有查找到,所以返回-1
遍历字符串
string str;
cin >> str;
int len = str.size();
for(int i=0;i<len;i++)
{
printf("%c",str[i]);
}
特别注意
字符串的整体输入输出不能使用scanf()和printf()

#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
getline(cin,a);
getline(cin,b);
for(int i=0;a[i];i++)
{
if(a[i]>='a'&&a[i]<='z')
a[i]-=32;
if(a[i]==' ')
{
a.erase(i,1);
i--;
}
}
for(int i=0;b[i];i++)
{
if(b[i]>='a'&&b[i]<='z')
b[i]-=32;
if(b[i]==' ')
{
b.erase(i,1);
i--;
}
}
// cout<<a<<endl<<b;
if(a==b)
{
cout<<"YES";
}
else{
cout<<"NO";
}
return 0;
}