I have code to read the file and print it out. I need to search for a string and replace it so I figured it would be better to do it in C++.
Can this be done in C++ to get the data in a string?Code:unsigned char ch; int linecounter=0; FILE *in; in = fopen("myfile.bin","rb"); if(ferror(in) ){ perror("Error opening input file:"); exit(1); } while (!feof(in) ){ if( fread(&ch,sizeof(ch),1,in) ==1){ /* do stuff with the character you just read */ printf("%c",ch); linecounter++; if ( !(linecounter%30) ) printf("\n"); } } fclose(in);




Reply With Quote