您的位置:首页 > 编程语言 > C语言/C++

sublime && c++ 配置问题

2013-06-04 00:11 218 查看
配置完gcc和sublime后,编译C++程序不显示结果

Ctrl+`   显示错误信息为

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 3: ordinal not in range(128)

这个问题的起因是配置文件目录下Packages\Default目录下的exec.py在编辑环境变量,但是环境变量中的字符集确少了ascii字符集

找到45行

for k, v in proc_env.iteritems():

 proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())

编码错误问题,打开C:\Users\stargazer\AppData\Roaming\Sublime Text 2\Packages\Default   里面的exec.py文件编辑

解决方法有:

1、果断删掉!(你没看错,就是这样)

2、对它进行异常处理,避免它出错时停止程序运行就像这样:

     for k, v in proc_env.iteritems():

            try:

                proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())

            except UnicodeDecodeError:

                print "Encoding error..."

                print "VARIABLE: ", k, " : ", v

然后你在尝试对pyhon或是其他程序的编译,就会发现切正常了!

要进行数据输入的话,重新配置builder文件

代码如下

{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}","-Wall" ,"&&","start","C:/cb_console_runner.exe","${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"encoding": "cp936",
"variants":
[
{
"name": "Run",
"cmd": ["start","C:/cb_console_runner.exe","${file_path}/${file_base_name}"]
}
]
}


其中 cb_console_runner.exe 需要单独下载,并放在英文目录下,设置环境变量。  

{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}","-Wall" ,"&&","start","C:/cb_console_runner.exe","${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": true,
"encoding": "cp936",
"variants":
[
{
"name": "Run",
"cmd": ["start","C:/cb_console_runner.exe","${file_path}/${file_base_name}"]
}
]
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐