SwitchGame/source/Tool/Ifstream_PVF.cpp

39 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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))
{
SDL_Log("文件读取成功,大小: %ld bytes", length);
}
else
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "文件读取不完整");
_Data.clear();
}
}
file.close();
}
else
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "无法打开文件: %s", fileName.c_str());
}
}
Ifstream_PVF::~Ifstream_PVF()
{
// vector会自动释放内存无需手动操作
}