问题

软件 >> C++ >> CodeBlocks
Questions in category: CodeBlocks (CodeBlocks).

CodeBlocks 文件编辑和程序编译的编码设置

Posted by haifeng on 2018-04-10 13:16:43 last update 2018-04-14 11:24:50 | Answers (0) | 收藏


如果编码不一致,则在编译时会出现下面的错误:

 

||=== Build: Release in Josephus (compiler: GNU GCC Compiler) ===|
D:\work\cs\c++\datastruct\Exercise\Josephus\main.cpp||In function 'int main()':|
D:\work\cs\c++\datastruct\Exercise\Josephus\main.cpp|34|error: converting to execution character set: Illegal byte sequence|
D:\work\cs\c++\datastruct\Exercise\Josephus\main.cpp|36|error: converting to execution character set: Illegal byte sequence|
D:\work\cs\c++\datastruct\Exercise\Josephus\main.cpp|38|error: converting to execution character set: Illegal byte sequence|
D:\work\cs\c++\datastruct\Exercise\Josephus\main.cpp|40|error: converting to execution character set: Illegal byte sequence|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

 

 

设置办法:

文件编码:
Setting -> Editor ->General settings -> Encoding settings

此处默认Windows-936即gbk

编译编码:
Setting -> Compiler -> Global compiler settings -> other compiler options

在框中输入:
    -finput-charset=GBK
    -fexec-charset=GBK

 

如果需要跨平台, 建议都设置为 UTF-8, 即

-finput-charset=UTF-8
-fexec-charset=UTF-8


References:

这里设置办法参考自

http://www.cnblogs.com/thingk/p/4224186.html