devkitPro / wut

Let's try to make a Wii U Toolchain / SDK for creating rpx/rpl.
zlib License
244 stars 52 forks source link

Writing files with std::ofstream does not work #146

Closed BullyWiiPlaza closed 4 years ago

BullyWiiPlaza commented 4 years ago

I found an "elegant" C++ solution to writing files which works fine on PC (tested on Windows and Linux) but does not work on Wii U. The following code always enters the successfully_written = false part (please note that the file does not exist yet and I'm trying to create a new one):

void write_string_to_file(const std::string &file_path,
                          const std::string &file_content, bool &successfully_written) {
    DEBUG_FUNCTION_LINE("Writing to file path \"%s\"...\n", file_path.c_str());
    std::ofstream file_writer(file_path, std::ios_base::binary);

    if (file_writer.fail()) {
        successfully_written = false;
        return;
    }

    file_writer << file_content;
    successfully_written = true;
}

The CFile class however works. Is there maybe an issue with the devoptab mapping or the flags being set by the std::ofstream constructor?

Maschell commented 4 years ago

Works for me without problems. Make sure to call file_writer.close() after writing to the file. Did the folder exist where you tried to write the file to?

EDIT: the issue is non-wut related and be closed.