//: C02:NumberPhotos.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Find the marker "XXX" and replace it with an // incrementing number whereever it appears. Used // to help format a web page with photos in it #include "../require.h" #include #include #include #include using namespace std; int main(int argc, char* argv[]) { requireArgs(argc, 2); ifstream in(argv[1]); assure(in, argv[1]); ofstream out(argv[2]); assure(out, argv[2]); string line; int counter = 1; while(getline(in, line)) { int xxx = line.find("XXX"); if(xxx != string::npos) { ostringstream cntr; cntr << setfill('0') << setw(3) << counter++; line.replace(xxx, 3, cntr.str()); } out << line << endl; } } ///:~