注册 登录
编程论坛 C++教室

读取16进制的文件然后显示出来~请进指教

nexus88 发布于 2007-01-07 00:05, 1095 次点击
有个AAA。BIN 里面是用16进制编写的文件
请问如何用VC++或者C来打开文件 并且让它显示在屏幕上 然后我要编辑它
3 回复
#2
pinglideyu2007-01-07 11:19

这个行不?
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>

void textread()
{
char ch;
ifstream readchar;
readchar.open("text1.dat");
if (!readchar)
{
cout<<"Error!Cannot open file!"<<endl;
exit(1);
}
while (readchar.get(ch))
cout.put(ch);
cout<<endl;
}
void main()
{
textread();
}

#3
nexus882007-01-07 13:13
不行哦 你没有转换16进 它是16进的文件 举2行例子给你们看
000000 58 00 00 00 59 03 C9 01 59 03 X...Y...Y...
000010 65 01 97 10 01 FF C9 10 97 01 e...e.e.....

是这样的
#4
shenql2008-04-16 21:34
#include<stdio.h>
#include<stdlib.h>
int print_bit(int i);
int main()
{
    FILE *infile,*outfile;
    int ch[50];
    char filename[20]="D:/test/test3.eti";
    int num1,i=0;
//    long num2;
    //double num3;

    infile = fopen(filename,"rb");
    outfile=fopen("D:/test.dat","wb");
    if (infile==NULL)
    {
        printf("\n The file %s was not successfullly opened!",filename);
        printf("\n Please check that the file currently exists.\n");
        exit(1);
    }

    fread(&num1,sizeof(num1),1,infile);
    
    //fread(&num2,sizeof(num2),1,infile);
    //fread(&num3,sizeof(num3),1,infile);

    fclose(infile);
    printf("The data input from the %s file is:",filename);
    printf("%x %d \n",num1,sizeof(filename[0]));
    
    //print_bit(num1);
    
    for(i=0;i<=49;i++)
        fwrite(&ch[i],sizeof(ch[i]),1,outfile);
    fclose(outfile);
    return 0;
}
1