sublime text編譯時提示錯誤[Decode error - output not utf-8] compilation terminated

食野之苹發表於2014-01-24

在ST3裡寫了一個C++程式,如下:

#include 
using namespace std;
int main()
{
	float a,b;
	char oper;
	cout <<"請輸入一個表示式(eg.1+2):" <>a >>oper >>b;
	if (oper=='+')
	{
		cout <
用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檔案


Java的參考部落格是:
http://blog.csdn.net/chszs/article/details/8232077
Python的參考部落格是:
http://www.cnblogs.com/muzizongheng/archive/2013/07/05/3172998.html

相關文章