如何在 C++ 中 wprintf 字符的值

问题描述 投票:0回答:1

如何打印一个字符(wstring)的Ascii值?

例如我想获取 Ö 的 Ascii 值,即 214。

我试过这个:

std::wstring ws2 = L"Ö";        
wprintf(L"This is wpritf for int: %ls(%i)...\n", ws2.c_str(), ws2.c_str());

但它给了我:

这是 int 的 wpritf:╓(5238748)...

c++ string integer char printf
1个回答
0
投票

您可以尝试使用顶部的

_setmode(_fileno(stdout), _O_WTEXT);

#include <io.h>
#include <fcntl.h>
#include <string>

int main(void) {
    _setmode(_fileno(stdout), _O_WTEXT);

    std::wstring ws2= L"Ö";

    wprintf(L"This is wpritf for int: %ls(%lc)...\n", ws2.c_str(), 214);

    return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.