V
V
Vadim Ushakov2022-02-25 21:32:36
linux
Vadim Ushakov, 2022-02-25 21:32:36

What is the problem with wofstream in linux?

In general, I decided to build a module for CentOS 9, but stumbled on the code

bool forceinline ForceWriteToFile(
        /* filepath. */ const std::wstring & filename,
        /* content body. */ const std::wstring & body)
    {
#ifdef __Windows__
        std::wofstream out(filename, std::ios::binary);
#else
        std::ofstream out(Machinarium::Utils::String::ToStdString(filename), std::ios::binary);
#endif

        if (out.fail()) {
            std::string a(filename.begin(), filename.end());
#ifdef Machinarium_Debug
            std::wcout << L"Failed to write to " << filename << L", FORCED unlinking." << std::endl;
#endif
            unlink(a.c_str());

#ifdef __Windows__
            out.open(filename);
#else
            out.open(Machinarium::Utils::String::ToStdString(filename));
#endif
            if (out.fail()) return false;
        }

#ifdef __Windows__
        out << body;
#else
        out << Machinarium::Utils::String::ToStdString(body);
#endif
        return true;
    }


This error occurs during compilation.

../src/Machinarium/Filesystem/FilesystemObject.cpp:106:86: ошибка: no matching function for call to «std::basic_ofstream<wchar_t>::basic_ofstream(std::wstring, std::_Ios_Openmode)»
  106 |         std::wofstream input(_path.wstring(), std::ofstream::out | std::ofstream::app);


Question. Why does a typing error occur, i.e. wofstream basically does not work or what? Didn't understand anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zerg89, 2022-02-27
@Zerg89

#ifdef __Windows__ std::wofstream out(filename, std::ios::binary); #else std::ofstream out(Machinarium::Utils::String::ToStdString(filename), std::ios::binary); #endif

Isn't there a typo else ofstream? As far as I understand, the wofstream variable is not filled

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question