售前咨询
技术支持
渠道合作

sublime text编译时提示错误[Decode error – output not utf-8] compilation terminated

在ST3里写了一个C++程序,如下:

 

#include <iostream>

using namespace std;

int main()

{

float a,b;

char oper;

cout <<“请输入一个表达式(eg.1+2):” <<endl;

cin >>a >>oper >>b;

if (oper==’+’)

{

cout <<a <<oper <<b <<‘=’ <<a+b <<endl;

}

else

{

if (oper==’-‘)

{

cout <<a <<oper <<b <<‘=’ <<a-b <<endl;

}

else

{

if (oper==’*’)

{

cout <<a <<oper <<b <<‘=’ <<a*b <<endl;

}

else

{

if (b!=0 && oper==’/’)

{

cout <<a <<oper <<b <<‘=’ <<a/b <<endl;

}

else

{

cout <<“出错啦!” <<endl;

}

}

}

}

return 0;

}

 

用ctrl+b编译后出现错误提示如下图:

[Decode error – output not utf-8]

compilation terminated.

[Finished in 0.1s]

 

经过百度,找到了一些针对python和java程序遇到这个问题的解决办法.

不过我的程序毕竟是c++,但我仍然找到了一些相同之处,通过试验果然解决掉了。

解决办法如下:

1、首先在Preferences里点击Browse Packages:

2、然后在里面找到User,点击进入:

3、找到C.sublime-build,点击打开文件,看到如下:

 

{

“cmd”: [“g++”, “${file}”, “-o”, “${file_path}/${file_base_name}”],

“file_regex”: “^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$”,

“working_dir”: “${file_path}”,

“selector”: “source.c, source.c++”,

 

“variants”:

[

{

“name”: “Run”,

“cmd”: [“cmd”, “/c”, “g++”, “${file}”, “-o”, “${file_path}/${file_base_name}”, “&&”, “cmd”, “/c”, “${file_path}/${file_base_name}”]

},

{

“name”: “RunInCommand”,

“cmd”: [“cmd”, “/c”, “g++”, “${file}”, “-o”, “${file_path}/${file_base_name}”, “&&”, “start”, “cmd”, “/c”, “${file_path}/${file_base_name} & pause”]

}

]

}

 

在文件的这个文本的”selector”: “source.c, source.c++”,下一行添加一个语句:

“encoding”:”cp936″,

注意有逗号

然后保存后,重启ST3,问题就解决啦。

另外针对python文件和java文件,修改的方法是一致的,只是要修改的文件不同:java是JavaC.sublime-build文件和Python.sublime-build文件。

上一篇:

下一篇:

相关文章