📄 utils.hpp
字号:
// (C) Copyright Chrstopher Diggins 2004 http://www.cdiggins.com
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
//
// Disclaimer: Not a Boost library
#ifndef UTILS_HPP_INCLUDED
#define UTILS_HPP_INCLUDED
#include <time.h>
#include <fstream>
#include <iostream>
class TimeIt {
public:
TimeIt() { mnStart = GetTickCount(); };
~TimeIt() { std::cout << "time elapsed (msec): " << GetMSecElapsed() << std::endl; };
int GetMSecElapsed() { return GetTickCount() - mnStart; };
int GetTickCount() { return int(double(clock()) * 1000 / CLOCKS_PER_SEC); };
private:
int mnStart;
};
unsigned int GetFileSize(const char * sFileName) {
std::ifstream f(sFileName, std::ios::binary);
if (!f.good()) { return 0; }
//std::ifstream::pos_type begin_pos = f.tellg();
long begin_pos = f.tellg();
f.seekg(0, std::ios::end);
return f.tellg() - begin_pos;
}
char * AllocFromFile(const char * sFileName) {
unsigned int n = GetFileSize(sFileName);
if (n == 0) return NULL;
char * ret = static_cast < char * > (calloc(n + 1, 1));
if (ret == NULL) return NULL;
std::ifstream f(sFileName, std::ios::binary);
f.read(ret, n);
f.close();
return ret;
}
#endif // UTILS_HPP_INLCUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -