c++ 小记1
2016-06-07 21:29
465 查看
1.../表示上一级文件夹
应该要把require.h放在这个工程中代码文件的上一级文件夹中
例如建一个projec工程,代码文件被放在project文件夹中,那就吧require.h放在project文件夹的上一级文件夹中
2.#include "../require.h"
一般这种是你自己写的头文件.一般库文件是用#include<iostream>这种尖括号的
3.require.h#ifndef REQUIRE_H
#define REQUIRE_H
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <string>
inline void require(bool requirement,
const std::string& msg = "Requirement failed"){
using namespace std;
if (!requirement) {
fputs(msg.c_str(), stderr);
fputs("\n", stderr);
exit(1);
}
}
inline void requireArgs(int argc, int args,
const std::string& msg =
"Must use %d arguments") {
using namespace std;
if (argc != args + 1) {
fprintf(stderr, msg.c_str(), args);
fputs("\n", stderr);
exit(1);
}
}
inline void requireMinArgs(int argc, int minArgs,
const std::string& msg =
"Must use at least %d arguments") {
using namespace std;
if(argc < minArgs + 1) {
fprintf(stderr, msg.c_str(), minArgs);
fputs("\n", stderr);
exit(1);
}
}
inline void assure(std::ifstream& in,
const std::string& filename = "") {
using namespace std;
if(!in) {
fprintf(stderr, "Could not open file %s\n",
filename.c_str());
exit(1);
}
}
inline void assure(std::ofstream& out,
const std::string& filename = "") {
using namespace std;
if(!out) {
fprintf(stderr, "Could not open file %s\n",
filename.c_str());
exit(1);
}
}
#endif
应该要把require.h放在这个工程中代码文件的上一级文件夹中
例如建一个projec工程,代码文件被放在project文件夹中,那就吧require.h放在project文件夹的上一级文件夹中
2.#include "../require.h"
一般这种是你自己写的头文件.一般库文件是用#include<iostream>这种尖括号的
3.require.h#ifndef REQUIRE_H
#define REQUIRE_H
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <string>
inline void require(bool requirement,
const std::string& msg = "Requirement failed"){
using namespace std;
if (!requirement) {
fputs(msg.c_str(), stderr);
fputs("\n", stderr);
exit(1);
}
}
inline void requireArgs(int argc, int args,
const std::string& msg =
"Must use %d arguments") {
using namespace std;
if (argc != args + 1) {
fprintf(stderr, msg.c_str(), args);
fputs("\n", stderr);
exit(1);
}
}
inline void requireMinArgs(int argc, int minArgs,
const std::string& msg =
"Must use at least %d arguments") {
using namespace std;
if(argc < minArgs + 1) {
fprintf(stderr, msg.c_str(), minArgs);
fputs("\n", stderr);
exit(1);
}
}
inline void assure(std::ifstream& in,
const std::string& filename = "") {
using namespace std;
if(!in) {
fprintf(stderr, "Could not open file %s\n",
filename.c_str());
exit(1);
}
}
inline void assure(std::ofstream& out,
const std::string& filename = "") {
using namespace std;
if(!out) {
fprintf(stderr, "Could not open file %s\n",
filename.c_str());
exit(1);
}
}
#endif
相关文章推荐
- C/C++输出格式运用
- c/C++ 田忌赛马(贪心算法)
- C++Primer 中文版 第五版 第六章课后习题答案
- C/C++ 银行存款N年本息和计算
- C++ 笔记6:String 和 string stream
- Search a 2D Matrix II
- 长方体的体积和面积
- C/C++指针与数组的关系
- C/C++运算符重载实现字符串相加
- C/C++ 虚函数
- C/C++ 重载+运算符重载加号 实现矩阵相加
- C_basic_summary--各种类型数据所占字节数
- Sliding Window Maximum
- 温习C/C++宏定义
- VC++ 数字图像处理第二章学习
- C++ 笔记5:LIST 和MAP
- leetcode 20 Valid Parentheses C++
- C/C++卡布列克运算验证
- C++ STL中Map的按Key排序和按Value排序
- 武器类属性