Try to search your question here, if you can't find : Ask Any Question Now ?

writing unicode characters to file

HomeCategory: stackoverflowwriting unicode characters to file
sourav asked 1 week ago

I’m trying to write unicode characters to file with std::wofstream but the put function doesn’t write any characters.

Sample code:

#include <fstream>
#include <iostream>

int main()
{
    std::wofstream file;
    file.open("output.txt", std::ios::app);
    if (file.is_open())
    {
        wchar_t test = L'й';
        const wchar_t* str = L"фывдлао";
        file.put(test);
        file.write(str, sizeof(str));
        file.close();
    }
    else
    {
        std::wcerr << L"Failed to open file" << std::endl;
    }

    std::cin.get();
    return 0;
}

output.txt file is empty, no wchar/string is written after executing code, why? what am I doing wrong?

1 Answers
Best Answer
Jyoti answered 1 week ago
Your Answer

15 + 5 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com