//File_IO.cpp //Binary and text files I/O demo #include "stdafx.h" #include #include #include #include using namespace std; void main(void) { // Create text and binary files with the SAME data FILE * num_t_out=fopen("c:\\temp\\num.txt","w"); FILE * num_b_out=fopen("c:\\temp\\num.bin","wb"); if(num_t_out != NULL && num_b_out != NULL ) { for(unsigned int i=1e9; i<1e9+20 ; i++) { fprintf(num_t_out,"%d ",i); //to text file fwrite(&i,sizeof(int),1,num_b_out); // to binary file } fclose(num_t_out); fclose(num_b_out); } else {cout<<"File problems\n"; getch(); exit(1);} // Read text file and binary file FILE * num_t_in=fopen("c:\\temp\\num.txt","r"); FILE * num_b_in=fopen("c:\\temp\\num.bin","rb"); if(num_t_in != NULL && num_b_in != NULL ) { cout<<"\nText file data\n\n"; while(1) { int tmp; fscanf(num_t_in,"%d",&tmp); if(feof(num_t_in)) break; cout<