下班了,读文件很简单:
#include <iostream>
#include <fstream>int main()
{
long i=0x0003e4f0+3;
std::fstream tfile("d:\\test.dat");
tfile.seekg(i);
char ch1;
char ch2;
tfile.get(ch1);
tfile.get(ch2);
std::cout<<ch1<<"\t"<<ch2<<std::endl;
tfile.close(); return 0;
}如果文件不大的话,可以将文件所有内容读到内存修改后再写回文件,如果文件大的话,可能就要只用临时文件(我的想法),不知道行不行
#include <iostream>
#include <fstream>int main()
{
long i=0x0003e4f0+3;
std::fstream tfile("d:\\test.dat");
tfile.seekg(i);
char ch1;
char ch2;
tfile.get(ch1);
tfile.get(ch2);
std::cout<<ch1<<"\t"<<ch2<<std::endl;
tfile.close(); return 0;
}如果文件不大的话,可以将文件所有内容读到内存修改后再写回文件,如果文件大的话,可能就要只用临时文件(我的想法),不知道行不行
处加括号的那段地址的值(73 2c),输出到屏幕!然后在原地址处修改为ff ff!
{
FILE *fp=fopen("TEST.dat","rw+");
fseek(fp,0X0003e4f3,SEEK_SET);
short i;
fread(&i,sizeof(short),1,fp);
printf("the item %d:",i);
i=0XFFFF;
fwrite(&i,sizeof(short),1,fp);
fclose(fp);
}
#include <iostream>
#include <fstream>int main()
{
long i=0x0003e4f0+3; //数据位置
std::ifstream ifile("d:\\test.dat",std::ios::in | std::ios::out); //读写方式打开文件
if(!ifile.fail())
{
char ch1;
char ch2;
ifile.seekg(i);
ifile.get(ch1); //读取连续的两个字符
ifile.get(ch2);
std::cout<<ch1<<"\t"<<ch2<<std::endl; std::ostream ofile(ifile.rdbuf()); //修改文件
ofile.seekp(-2,std::ios::cur); //返回数据修改位置
ofile.put('x'); //修改连续的两个字符
ofile.put('x');
ifile.seekg(0,std::ios::beg); //到文件头
std::cout<<ifile.rdbuf()<<std::endl; //显示修改后的数据
ifile.close();
}
return 0;
}
但是我编译后有点问题!不能写入不敷出ffff,您能帮我再看看么?
除了这贴的分数,另一百分离你不远了~呵呵 !其他高手有高见么?!
在fwrite和fread之间必须有个指针重新定位的过程!我自己已经想出办法了!
马上结分请路过的人发言~如果需要程序范例的话~进来UP!
main()
{
FILE *f;
unsigned char buffer[BUFFERSIZE];
int i=0x0003e4f0;
int n=0xff; if( (f = fopen("text.txt","r+b"))==NULL)
{
printf("file not found!\n");
return(0);
} fseek(f,i,SEEK_SET);
fread(buffer,sizeof(char),BUFFERSIZE,f);
printf("%d,%d",buffer[0],buffer[1]); fseek(f,i,SEEK_SET);
fprintf(f,"%c",n);
return(0);}
main()
{
FILE *f;
unsigned char buffer[BUFFERSIZE];
int i=0x0003e4f0;
int n=0xff; if( (f = fopen("text.txt","r+b"))==NULL)
{
printf("file not found!\n");
return(0);
} fseek(f,i,SEEK_SET);
fread(buffer,sizeof(char),BUFFERSIZE,f);
printf("%d,%d",buffer[0],buffer[1]); fseek(f,i,SEEK_SET);
fprintf(f,"%c",n);
fprintf(f,"%c",n);
return(0);}
main()
{
FILE *f;
unsigned char buffer[BUFFERSIZE];
int i=0x0003e4f3;
int n=0xff;
if( (f = fopen("u88.unf","r+b"))==NULL)
{
printf("file not found!\n");
return(0);
} fseek(f,i,SEEK_SET);
fread(buffer,sizeof(char),BUFFERSIZE,f);
printf("%d,%d\n",buffer[0],buffer[1]);
fseek(f,i,SEEK_SET);
fprintf(f,"%c",n);
fseek(f,i+1,SEEK_SET);
fprintf(f,"%c",n);
fseek(f,i,SEEK_SET);
fread(buffer,sizeof(char),BUFFERSIZE,f);
printf("%d,%d\n",buffer[0],buffer[1]); return(0);}
够清楚没?