CppCommon  1.0.4.1
C++ Common Library
filesystem_file.cpp

Filesystem file example

#include <iostream>
int main(int argc, char** argv)
{
char buffer[] = "The quick brown fox jumps over the lazy dog";
// Create file for writing
CppCommon::File file("example.txt");
file.Create(false, true);
// Write buffer into the file
file.Write(buffer, CppCommon::countof(buffer) - 1);
// Flush the file
file.Flush();
// Close the file
file.Close();
std::cout << "File size: " << file.size() << std::endl;
// Read all text from the file
std::string text = CppCommon::File::ReadAllText(file);
std::cout << "File content: " << text << std::endl;
// Remove file
return 0;
}
Filesystem file.
Definition: file.h:28
void Close()
Close the file.
Definition: file.cpp:765
uint64_t size() const
Get the current file size.
Definition: file.cpp:713
void Flush() override
Flush the file.
Definition: file.cpp:764
void Create(bool read, bool write, const Flags< FileAttributes > &attributes=File::DEFAULT_ATTRIBUTES, const Flags< FilePermissions > &permissions=File::DEFAULT_PERMISSIONS, size_t buffer=File::DEFAULT_BUFFER)
Create a new file.
Definition: file.cpp:755
size_t Write(const void *buffer, size_t size) override
Write a byte buffer into the opened file.
Definition: file.cpp:760
std::string ReadAllText()
Read all text.
Definition: reader.cpp:32
static Path Remove(const Path &path)
Remove the given path (file, empty directory, symlink, etc) from the filesystem.
Definition: path.cpp:1209
Static array countof definition.
Filesystem file definition.
constexpr size_t countof(const T(&)[N]) noexcept
Count of elements in static array.
Definition: countof.h:16