很多人经常需要把代码分别在linux、windows上编译。在linux中gcc编译的时候,文件格式为utf-8无bom格式,可是如果将文件拿到windows上,用vs编译的时候,发现各种报错,且都是不知道原因的错误,这个时候就要考虑代码中注释部分含有中文汉字,导致的。废话不多说,直接说解决方案。
注释的时候,使用一下方案就可以解决这个问题了。
/(空格)注释的内容(空格)/
这个需要设置下行尾问题, 需要切换至
其实只要对应编码代码也对了, 其他的都会正确。
问题 UTF-8 无 BOM 乱码;UTF-8 无 BOM "常量中有换行符"错误提示;window cmd UTF-8 无 BOM 显示乱码;
UTF-8 without BOM garbled; UTF-8 without BOM "Line breaks in constants" error message; window cmd UTF-8 without BOM shows garbled characters;
warning 4819
另一种解决方法是在c++写上/utf-8编译, 如果是无标签的utf,msvc会默认当作 ansi 解析