Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

glog print wchar_t? #64

@wqingzex

Description

@wqingzex

I write this code to print wchar_t using glog:

std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) {
    std::mbstate_t state = std::mbstate_t();
    int len = 1 + std::wcsrtombs(nullptr, &wstr, 0, &state);
    std::vector<char> mbstr(len);
    std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state);

    out << &mbstr[0];
    return out;
}

std::ostream& operator<<(std::ostream& out, const std::wstring& str) {
   return operator<<(out, str.c_str());
}

but it does not work, why??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions