readlower.h
来自「Thinking in C++ 2nd edition source code 」· C头文件 代码 · 共 39 行
H
39 行
//: C26:readLower.h
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Read a file into a container of string,
// forcing each line to lower case.
#ifndef READLOWER_H
#define READLOWER_H
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cctype>
#include "../require.h"
inline char downcase(char c) {
using namespace std; // Compiler bug
return tolower(c);
}
std::string lcase(std::string s) {
std::transform(s.begin(), s.end(),
s.begin(), downcase);
return s;
}
template<class SContainer>
void readLower(char* filename, SContainer& c) {
std::ifstream in(filename);
assure(in, filename);
const int sz = 1024;
char buf[sz];
while(in.getline(buf, sz))
// Force to lowercase:
c.push_back(string(lcase(buf)));
}
#endif // READLOWER_H ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?