编写了 tools.h
和 tools.cpp
,用于 Debug、性能测试、打印日志。
tools.h
#ifndef TOOLS_H
#define TOOLS_H
#include <time.h>
#include <fstream>
#include <iostream>
#include <random>
#include <chrono>
#include <vector>
#include <algorithm>
using namespace std;
// 换行
#define pn puts("")
// 代码位置
#define where printf("File: %s, Line: %d, Function: %s. ", __FILE__, __LINE__, __FUNCTION__)
// 打印错误
#define ErrorInfo(format, ...) \
{
\
printf("[Error] "); \
where; \
printf(format, ##__VA_ARGS__); \
pn; \
}
// 捕获异常
#define Try(code) \
try \
{
\
code; \
} \
catch (const std::exception &e) \
{
\
std::cerr << "Catch exception: " << e.