I've written a little tool for myself to split a long text file into several shorter ones. (Probably re-invented to wheel too. Heh.)
The bit I'm concerned about follows. The question is: is it possible to avoid write/read to buffer in a trivial way in an effort to improve the execution speed?
P.S.Code:int counter = 0; char buffer[1025]; while (inFile.good()) { char outname[256]; if (df) { sprintf(outname, ".\\%s\\%s%i.txt", basename, basename, counter); } else { sprintf(outname, "%s%i.txt", basename, counter); } std::ofstream outFile(outname); if (!outFile.is_open()) { std::cout << "Output file " << outname << " could not be written.\nInterrupting.\n" "Clean up and restart the program.\n"; return 1; } for (int i = 1; i <= lines && inFile.good(); i++) { inFile.getline(buffer, 1025); outFile << buffer << '\n'; } outFile.close(); std::cout << "File " << outname << " written successfully.\n"; counter++; }
Feel free to suggest improvements where they can be made.



LinkBack URL
About LinkBacks




