#include #include #include #include #include #include
// file read buffer toolclass BufferFile
{
public:
std::string file_path_;
std::size_t length_ = 0;
std::unique_ptr buffer_;
explicit BufferFile(const std::string &file_path)
: file_path_(file_path)
{
std::ifstream ifs(file_path.c_str(), std::ios::in | std::ios::binary);
if (!ifs)
{
std::cerr << "Can't open the file. Please check " << file_path << std::endl;
return;
}
ifs.seekg(0, std::ios::end);
length_ = static_cast<:size_t>(ifs.tellg());
ifs.seekg(0, std::ios::beg);
std::cout << file_path.c_str() << " ... " << length_ << " bytes\n";
buffer_.reset(new char[length_]);
ifs.read(buffer_.get(), length_);