文件操作
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fin("in.txt");
char c;
fin>>c;
cout<<c;
fin.close();
return 0;
}
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
char c;
cin>>c;
cout<<c;
fclose(stdin);
return 0;
}
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
FILE * fin;
fin=fopen("in.txt","rb");
char c;
fscanf(fin,"%c",&c);
cout<<c;
fclose(stdin);
return 0;
}
string.find()
https:
s.find(str);返回第一个起始下标
s.rfind(str);从右边找,返回右边第一个子串位置的起始下标
s.find_first_of(str);返回第一个起始下标 ==s.find()
s.find_last_of(str);返回最后一个子串的末尾字符下标
string s="0123456789";
cout<<s.find("789")
cout<<s.rfind("789")
cout<<s.find_first_of("789");
cout<<s.find_last_of("789");
string.replace
s1.replace(s1.find(s2),s2.size(),"",0,0);
s.replace(0,1,"abc",0,2);
s.replace(0,1,"abc");
5个参数:s1开始下标 s1被替换的长度 s2 s2开始下标 s2的去替换的长度
string.substr
s1.substr(2, 4);
s1.substr(2);
string.erase
s1.erase(1, 3);
s1.erase(1);
string.insert
s1.insert(3, s2);
s1.insert(3, 5, 'X');注意插入的是字符了
STL::find()