unsigned short chunk_id; // unsigned int chunk_len; // // , ifs ifstream ifs; // fname, ifs.open(fname.c_str(), ios_base::in | ios_base::binary | ios_base::beg); ifs.fail(); // ? // chunk_id 2 ; // "(char*)&" ifs.read((char*)&chunk_id,2); // chunk_len-6 ; chunk_len-6 ifs.ignore(chunk_len-6); // ifs.tellg()-6 ifs.seekg(ifs.tellg()-6); // ifs.tellg(); // ? ifs.eof(); . read write ">>" "<<" . . #include <cstdlib> #include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv[]) { char buffer[1]; int i; long currentpos; /* ( streampos ( pos_type ANSI C++))*/ bool match = false; if (argc != 5) { cout << "Usage: filter [search string] [replace string] [infile] [outfile]" << endl; return 1; } string searchstring = argv[1]; string replacestring = argv[2]; string infilename = argv[3]; string outfilename = argv[4]; // ( ) ifstream input(infilename.c_str(), ios::in); if (input.fail()) { cout << "Unable to open input file!" << endl; return 1; } // ( ) ofstream output(outfilename.c_str(), ios::out | ios::trunc); if (output.fail()) { cout << "Unable to open output file!" << endl; return 1; } while (!input.eof()) { currentpos = input.tellg(); // input.read(buffer, sizeof(buffer)); // ">>" if (buffer[0] == searchstring[0]) { match = true; i = 1; while (i < searchstring.length() && match) { input.read(buffer, sizeof(buffer)); if (buffer[0] != searchstring[i]) { input.seekg(currentpos); // // input.read(buffer, sizeof(buffer)); match = false; } else i++; } } if (match) { output.write(replacestring.c_str(), replacestring.length()); match = false; } else output.write(buffer, sizeof(buffer)); // "<<" } input.close(); output.close(); ifstream display(outfilename.c_str(), ios::in); // while (!display.eof()) { display.read(buffer, sizeof(buffer)); if (display.good()) cout << buffer[0]; } display.close(); return 0; } >> , . , . , - -. |
Нет комментариев. Оставить комментарий: |