建档
This commit is contained in:
35
source/Tool/Ifstream_PVF.cpp
Normal file
35
source/Tool/Ifstream_PVF.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "Ifstream_PVF.h"
|
||||
Ifstream_PVF::Ifstream_PVF(std::string fileName)
|
||||
{
|
||||
std::ifstream file(fileName, std::ios::binary | std::ios::in);
|
||||
if (file.is_open())
|
||||
{
|
||||
// 获取文件大小
|
||||
file.seekg(0, std::ios::end);
|
||||
std::streamsize length = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
// 直接调整vector大小并读取数据
|
||||
_Data.resize(static_cast<size_t>(length));
|
||||
if (file.read(_Data.data(), length))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
_Data.clear();
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "无法打开文件: %s", fileName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Ifstream_PVF::~Ifstream_PVF()
|
||||
{
|
||||
// vector会自动释放内存,无需手动操作
|
||||
}
|
||||
Reference in New Issue
Block a user