Add file IO functions
This commit is contained in:
parent
986719a405
commit
1f1e62abdc
@ -1,5 +1,5 @@
|
|||||||
# NF library CMakeLists.txt
|
# NF library CMakeLists.txt
|
||||||
add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/EngineConfig.h" "src/util/util.cpp")
|
add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/EngineConfig.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp")
|
||||||
|
|
||||||
# Use C++20
|
# Use C++20
|
||||||
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
#include "util/file.h"
|
||||||
|
|
||||||
// Define NFTime
|
// Define NFTime
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
25
NothinFancy/src/util/file.cpp
Normal file
25
NothinFancy/src/util/file.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// File IO functions implementation
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
namespace nf::util {
|
||||||
|
bool readFile(const char* filename, std::string& out) {
|
||||||
|
std::ifstream fileStream(filename, std::ios::binary | std::ios::ate);
|
||||||
|
if (!fileStream.is_open())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
size_t fileSize = fileStream.tellg();
|
||||||
|
out.resize(fileSize);
|
||||||
|
fileStream.seekg(0);
|
||||||
|
fileStream.read(out.data(), fileSize);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool writeFile(const char* filename, const std::string& in) {
|
||||||
|
std::ofstream fileStream(filename, std::ios::binary | std::ios::trunc);
|
||||||
|
if (!fileStream.is_open())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fileStream << in;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
7
NothinFancy/src/util/file.h
Normal file
7
NothinFancy/src/util/file.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// File IO functions header
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace nf::util {
|
||||||
|
bool readFile(const char* filename, std::string& out);
|
||||||
|
bool writeFile(const char* filename, const std::string& in);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user