因为结构体它里面有多种数据, 所以如果一个一个保存肯定是麻烦的. 所以, 如果保存的文件不是给用户看的, 而是只为程序所用, 那么直接用二进制方式打开文件, 然后用fwrite把结构的二进制数据写入内存#include<stdio.h>structdat{inti;charch;doubled;};intmain(){FILE *p=fopen("data.txt","w");if(!p)return0;fwrite(&p,sizeof(p),1,p);fclose(p);}用C语言实现。把结构体写入文件,然后再读取出来并显示;/* structinfile .c*Auther: tweety*date:2009-12-04*/#include<stdio.h>typedef structFilenode{intisempty;char*data;}filenode;intnode_init(filenode*node){node->isempty=1;node->data="FOOLisENOUGH!";return0;}intnode_write_infile(filenode*node){//把结构体写入文件FILE*fp=fopen("file.txt","w");if(fwrite(node,sizeof(Filenode),1,fp)){fclose(fp);return1;}elsereturn0;}intnode_read_outfile(filenode*node){//读取结构体FILE*fp=fopen("file.txt","r");if(fread(node,sizeof(Filenode),1,fp)){fclose(fp);return1;}elsereturn0;}intmain(){filenode*innode= malloc(sizeof(filenode));filenode*outnode=malloc(sizeof(filenode));node_init(innode);if(node_write_infile(innode))printf("file write OK\n");if(node_read_outfile(outnode)){printf("%d\n",outnode->isempty);printf("%s\n",outnode->data);}system("pause");return0;}