C++常用程序记录
C++常用程序记录
1.读取文件,替换指定字符串为另一字符串。
稍微改改,就可以变成替换指定字节数组了
朴实无华的操作,只能替换等长的内容
代码:
#include
#include
using namespace std;
int main()
{
string oldStr = "helloworld";
string newStr = "xxhhaabbcc";
int length = oldStr.length();
unsigned char* oldBytes = (unsigned char*)oldStr.c_str();
unsigned char* newBytes = (unsigned char*)newStr.c_str();
string filename = "";
cout<<"请输入文件名"<>filename;
FILE* fp = fopen(filename.c_str(),"rb");
fseek(fp,0,SEEK_END);
int len = ftell(fp);
fseek(fp,0,SEEK_SET);
unsigned char data[len];
fread(data,1,len,fp);
fclose(fp);
int count = 0;
for(int i;i>filename;
fp = fopen(filename.c_str(),"wb");
fwrite(data,1,len,fp);
fclose(fp);
}
后续有用到其他的,再更新吧。