![]() |
| | #1 |
| Novice Join Date: Jul 2009
Posts: 32
| File I/O loop. 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? 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. |
| msh is offline | |
| | #2 | |
| Ex scientia vera Join Date: Sep 2007
Posts: 426
| Quote:
__________________ "What's up, Doc?" "'Up' is a relative concept. It has no intrinsic value." | |
| IceDane is offline | |
| | #3 |
| Novice Join Date: Jul 2009
Posts: 32
| I love my arrays. ![]() But yea, you're right. I should rewrite it using strings. |
| msh is offline | |
![]() |
| Tags |
| file, i/o |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gcc link external library | spank | C Programming | 6 | 08-08-2007 03:44 PM |
| C++ std routines | siavoshkc | C++ Programming | 33 | 07-28-2006 12:13 AM |
| File I/O problem | 81N4RY_DR460N | C++ Programming | 12 | 09-03-2005 12:14 PM |
| Possible circular definition with singleton objects | techrolla | C++ Programming | 3 | 12-26-2004 10:46 AM |
| How do you search & sort an array? | sketchit | C Programming | 30 | 11-03-2001 05:26 PM |