📄 findblanks.cpp
字号:
//: C05:FindBlanks.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Demonstrate mem_fun_ref() with string::empty()
#include "../require.h"
#include <algorithm>
#include <list>
#include <string>
#include <fstream>
#include <functional>
using namespace std;
typedef list<string>::iterator LSI;
LSI blank(LSI begin, LSI end) {
return find_if(begin, end,
mem_fun_ref(&string::empty));
}
int main(int argc, char* argv[]) {
requireArgs(argc, 1);
ifstream in(argv[1]);
assure(in, argv[1]);
list<string> ls;
string s;
while(getline(in, s))
ls.push_back(s);
LSI lsi = blank(ls.begin(), ls.end());
while(lsi != ls.end()) {
*lsi = "A BLANK LINE";
lsi = blank(lsi, ls.end());
}
string f(argv[1]);
f += ".out";
ofstream out(f.c_str());
copy(ls.begin(), ls.end(),
ostream_iterator<string>(out, "\n"));
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -