下班了,读文件很简单:
#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;
}如果文件不大的话,可以将文件所有内容读到内存修改后再写回文件,如果文件大的话,可能就要只用临时文件(我的想法),不知道行不行

解决方案 »

  1.   

    这是用ULTRAEDIT32编辑某文件后得到的地址,现在需要先读出0003e4f0h
    处加括号的那段地址的值(73 2c),输出到屏幕!然后在原地址处修改为ff ff!
      

  2.   

    main()
    {
       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);
    }
      

  3.   

    一个完整的读写文件的例子,测试通过VC6.0:
    #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;
    }
      

  4.   

    deadwolf(死狼)您的程序能正确读出地址上的数字用十进制输到屏幕上,
    但是我编译后有点问题!不能写入不敷出ffff,您能帮我再看看么?
    除了这贴的分数,另一百分离你不远了~呵呵 !其他高手有高见么?!
      

  5.   

    hydnoahark(诺亚方舟)您忘记了我的程序是对十六进制的修改!!非长感激您对我的关注,自然有分
      

  6.   

    呵呵~死狼!
    在fwrite和fread之间必须有个指针重新定位的过程!我自己已经想出办法了!
    马上结分请路过的人发言~如果需要程序范例的话~进来UP!
      

  7.   

    #include "stdio.h"#define BUFFERSIZE 2
    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);}
      

  8.   

    #include "stdio.h"#define BUFFERSIZE 2
    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);}
      

  9.   

    #include "stdio.h"#define BUFFERSIZE 2
    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);}
    够清楚没?
      

  10.   

    printf("the item %Xh:",i);  十六进制输出嘿嘿  fwrite 前确实还有个重定位问题  既然你已经解决了  我就不写了