numberphotos.cpp
来自「This is the second part of that lab manu」· C++ 代码 · 共 33 行
CPP
33 行
//: C05:NumberPhotos.cpp
// From "Thinking in C++, 2nd Edition, Volume 2"
// by Bruce Eckel & Chuck Allison, (c) 2001 MindView, Inc.
// Available at www.BruceEckel.com.
// 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 <fstream>
#include <sstream>
#include <iomanip>
#include <string>
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;
}
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?