Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

cmake 通过message打印中文字符时会卡住,这可能是什么原因

  1. User

    cmake 通过message打印中文字符时会卡住,这可能是什么原因

  2. Assistant

    可能是因为cmake默认使用的是ASCII编码,在输出中文字符时会出现编码问题导致卡住。解决方法可以是在CMakeLists.txt文件的开头加入以下代码:

    cmake_minimum_required(VERSION 3.0)
    project(your_project)
    
    set(CMAKE_CXX_STANDARD 11)
    
    # 设置编码格式为UTF-8
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fexec-charset=UTF-8")
    

    其中,-fexec-charset=UTF-8的意思是设置C++文件的编码格式为UTF-8,从而可以正确输出中文字符。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.