Skip to content

build/api-examples/File.cpp

Complete program from the File API reference. Save it at the path shown above and use the build command in the reference page.

Source files · Download File.cpp

#include "gaspardos.hpp"
#include <cstdio>
#include <cstring>

int main()
{
    gaspardos::File file;
    if (!file.open("/AHCIDISK0/readme.txt", "rb"))
        return 1;
    char        data[128];
    std::size_t count  = file.read(data, sizeof(data));
    int         failed = file.error();
    std::printf("%lu bytes\n", static_cast<unsigned long>(count));
    return file.close() == 0 && !failed ? 0 : 1;
}