CodeLite 18编译输出中文乱码问题

在 CodeLite 中编译代码时,中文输出乱码通常是因为控制台编码设置不正确。你可以通过以下几种方式解决这个问题:

设置控制台编码

Windows 控制台中,你可以通过设置代码页(SetConsoleOutputCP(CP_UTF8);)来改变字符编码。你可以在代码中添加以下行来设置控制台为 UTF-8 编码:

#include <windows.h>
#include <stdio.h>

int main() {
    // 设置控制台为 UTF-8 编码
    SetConsoleOutputCP(CP_UTF8);
    
    // 其余代码...
}
#include <windows.h>
#include <stdio.h>

int main() {
    HKEY hKey;
    LONG result;
    char value[256];
    DWORD valueLength = sizeof(value);
    SetConsoleOutputCP(CP_UTF8);

    // 打开注册表键
    result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey);
    if (result != ERROR_SUCCESS) {
        printf("无法打开注册表键。错误代码: %ld\n", result);
        return 1;
    }

    // 查询注册表值
    result = RegQueryValueEx(hKey, "ProductName", NULL, NULL, (LPBYTE)value, &valueLength);
    if (result == ERROR_SUCCESS) {
        printf("Windows 产品名称: %s\n", value);
    } else {
        printf("无法读取注册表值。错误代码: %ld\n", result);
    }

    // 关闭注册表键
    RegCloseKey(hKey);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值