chore: extract io function to file
This commit is contained in:
parent
d845c71385
commit
6f5a70981d
|
@ -24,7 +24,7 @@ elseif(APPLE)
|
|||
message(FATAL_ERROR "macOS is not supported yet.")
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} hello.cpp)
|
||||
add_executable(${PROJECT_NAME} hello.cpp io.cpp)
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
|
|
20
hello.cpp
20
hello.cpp
|
@ -40,29 +40,11 @@
|
|||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
std::string readFile(const std::string& filePath)
|
||||
{
|
||||
std::ifstream fileStream(filePath, std::ios::in);
|
||||
|
||||
if (!fileStream.is_open())
|
||||
{
|
||||
std::cerr << "Could not read file " << filePath <<
|
||||
". File does not exist." << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::stringstream sstr;
|
||||
sstr << fileStream.rdbuf();
|
||||
fileStream.close();
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
#include "io.hpp"
|
||||
|
||||
GLuint compileShader(const std::string& shaderPath, GLenum shaderType)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#include "io.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
std::string readFile(const std::string& filePath)
|
||||
{
|
||||
std::ifstream fileStream(filePath, std::ios::in);
|
||||
|
||||
if (!fileStream.is_open())
|
||||
{
|
||||
std::cerr << "Could not read file " << filePath <<
|
||||
". File does not exist." << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::stringstream sstr;
|
||||
sstr << fileStream.rdbuf();
|
||||
fileStream.close();
|
||||
|
||||
return sstr.str();
|
||||
}
|
Loading…
Reference in New Issue