MCPcopy Create free account
hub / github.com/SFML/SFML / getFileContents

Function getFileContents

src/SFML/Graphics/Shader.cpp:83–100  ·  view source on GitHub ↗

Read the contents of a file into an array of char

Source from the content-addressed store, hash-verified

81
82// Read the contents of a file into an array of char
83bool getFileContents(const std::filesystem::path& filename, std::vector<char>& buffer)
84{
85 if (auto file = std::ifstream(filename, std::ios_base::binary))
86 {
87 file.seekg(0, std::ios_base::end);
88 const std::ifstream::pos_type size = file.tellg();
89 if (size > 0)
90 {
91 file.seekg(0, std::ios_base::beg);
92 buffer.resize(static_cast<std::size_t>(size));
93 file.read(buffer.data(), static_cast<std::streamsize>(size));
94 }
95 buffer.push_back('\0');
96 return true;
97 }
98
99 return false;
100}
101
102// Read the contents of a stream into an array of char
103bool getStreamContents(sf::InputStream& stream, std::vector<char>& buffer)

Callers 1

loadFromFileMethod · 0.85

Calls 2

resizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected