⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numberphotos.cpp

📁 Think in C++ 第二版源码
💻 CPP
字号:
//: C18:NumberPhotos.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// 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 <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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -