fix: build error on old C++ std

This commit is contained in:
MistEO
2024-11-19 19:11:30 +08:00
parent f5ccf62fda
commit 1bbba6fbe3

View File

@@ -16,7 +16,6 @@
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <filesystem>
#include <string_view> #include <string_view>
#ifdef _WIN32 #ifdef _WIN32
@@ -55,7 +54,12 @@ FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) {
return *this; return *this;
} }
using os_string = std::filesystem::path::string_type; // using os_string = std::filesystem::path::string_type;
#ifdef _WIN32
using os_string = std::wstring;
#else
using os_string = std::string;
#endif
os_string to_osstring(std::string_view utf8_str) os_string to_osstring(std::string_view utf8_str)
{ {
@@ -74,12 +78,13 @@ bool ReadBinaryFromFile(const std::string& path, std::string* contents)
if (!contents) { if (!contents) {
return false; return false;
} }
auto& result = *contents;
result.clear();
std::ifstream file(to_osstring(path), std::ios::binary | std::ios::ate); std::ifstream file(to_osstring(path), std::ios::binary | std::ios::ate);
if (!file.is_open()) { if (!file.is_open()) {
return false; return false;
} }
auto& result = *contents;
result.clear();
auto fileSize = file.tellg(); auto fileSize = file.tellg();
if (fileSize != -1) { if (fileSize != -1) {