require.h
来自「C++编程思想的源代码。需要的朋友就下载吧。都是已经写好了的源代码。」· C头文件 代码 · 共 71 行
H
71 行
//: :require.h
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
// Test for error conditions in programs.
#ifndef REQUIRE_H
#define REQUIRE_H
#include <cstdio>
#include <cstdlib>
#include <fstream>
inline void require(bool requirement,
const char* msg = "Requirement failed") {
// Local "using namespace std" for old compilers:
using namespace std;
if(!requirement) {
fputs(msg, stderr);
fputs("\n", stderr);
exit(EXIT_FAILURE);
}
}
inline void requireArgs(int argc, int args,
const char* msg = "Must use %d arguments") {
using namespace std;
if(argc != args + 1) {
fprintf(stderr, msg, args);
fputs("\n", stderr);
exit(EXIT_FAILURE);
}
}
inline void requireMinArgs(int argc, int minArgs,
const char* msg = "Must use at least %d arguments") {
using namespace std;
if(argc < minArgs + 1) {
fprintf(stderr, msg, minArgs);
fputs("\n", stderr);
exit(EXIT_FAILURE);
}
}
inline void assure(std::ifstream& in,
const char* filename = "") {
using namespace std;
if(!in) {
fprintf(stderr, "Could not open file %s\n", filename);
exit(EXIT_FAILURE);
}
}
inline void assure(std::ofstream& in,
const char* filename = "") {
using namespace std;
if(!in) {
fprintf(stderr, "Could not open file %s\n", filename);
exit(EXIT_FAILURE);
}
}
inline void assure(std::fstream& in,
const char* filename = "") {
using namespace std;
if(!in) {
fprintf(stderr, "Could not open file %s\n", filename);
exit(EXIT_FAILURE);
}
}
#endif // REQUIRE_H ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?