第5次实验题目-1
文件“round1.exe”文件请进行如下变换:
1、读取文件内容0-125000到字符串s1(共125001个字符)
2、读取文件剩余内容到字符串s2(共n-125001个字符)
3、字符串s=s2+s1
4、在s中搜寻“18606311394”,替换为“18606310394”
5、将s串写入文件6、运行变换后的文件,有惊喜!
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class File
{
private:
fstream f;
// ofstream f1;
string s,s1,s2;
long n;
public:
File()
{
f.open("round1.exe",ios::binary|ios::in|ios::out);
// f1.open("round3.exe",ios::in);
}
~File()
{
f.close();
// f1.close();
}
void change()
{
f.seekg(0,ios::end);
n=f.tellg();
s.resize(n);
f.seekg(0,ios::beg);
f.read((char*)s.c_str(),n);
string s1=s.substr(0,125001);
string s2=s.substr(125001,n-125001);
string s3=s2+s1;
long a;
a=s3.find("18606311394",0);
string s4="18606311394";
s3.replace(a,s4.size(),"18606310394");
f.seekp(0,ios::beg);
f.write((char*)s3.c_str(),n);
}
/*void Write()
{
f.seekp(0,i os::beg);
f.write((char*)s.c_str(),s.size());
}
void Read()
{
f.seekg(0,ios::end);
int n=f.tellg();
s.resize(n);
f.read((char*)s.c_str(),n);
cout<<s<<endl;
}*/
};
int main()
{
File f;
f.change();
return 0;
}