如何让你的Sublime和Codeblocks支持C++11 (转载)
2014-01-11 21:50
369 查看
转自:http://www.360doc.com/content/13/0913/11/9200790_314152981.shtml
闲来没事看了一下C++11,比起C++0x多了很多新功能,像auto变量,智能指针等,g++4.7以上版本也提供了对C++11的支持,但是,如何在你的编辑器上执行C++11代码呢?
刚开始以为用法和以前的版本一样,于是写了个C++11的小代码:
完事后一编译发现不对,于是又手工调用g++编译了一下:
发现还是不对。
百度了一下才发现原来编译C++11不同于C++0x,要加一个编译选项-std=c++11 :
编译顺利通过!!!
可是,如何将这个编译选项应用到IDE上呢?
我常用的编辑器是Codeblocks和Sublime
找了一下,其实Codeblocks的设置蛮简单的:
Setting->Compiler
直接在“Have g++ follow the C++11 ISO C++ language standard [-std=c++11]” 选项上打勾 保存就可以了
Sunlime的配置则比较麻烦一些:
Tools->Build System->New Build System...
然后把下面的代码粘贴到新打开的文件中:
然后保存,在保存文件对话框中把文件名字改成“C++11.sublime-build” 保存即可
然后选择Tools->Build System->C++11
这时你的Sublime Text就是一个完美的支持C++11的编辑器了!
闲来没事看了一下C++11,比起C++0x多了很多新功能,像auto变量,智能指针等,g++4.7以上版本也提供了对C++11的支持,但是,如何在你的编辑器上执行C++11代码呢?
刚开始以为用法和以前的版本一样,于是写了个C++11的小代码:
完事后一编译发现不对,于是又手工调用g++编译了一下:
g++ -o test2 test2.cpp
发现还是不对。
百度了一下才发现原来编译C++11不同于C++0x,要加一个编译选项-std=c++11 :
g++ -std=c++11 -o test2 test2.cpp
编译顺利通过!!!
可是,如何将这个编译选项应用到IDE上呢?
我常用的编辑器是Codeblocks和Sublime
找了一下,其实Codeblocks的设置蛮简单的:
Setting->Compiler
直接在“Have g++ follow the C++11 ISO C++ language standard [-std=c++11]” 选项上打勾 保存就可以了
Sunlime的配置则比较麻烦一些:
Tools->Build System->New Build System...
然后把下面的代码粘贴到新打开的文件中:
1 { 2 "cmd": ["g++", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"], // For GCC On Windows and Linux 3 //"cmd": ["CL", "/Fo${file_base_name}", "/O2", "${file}"], // For CL on Windows Only 4 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", 5 "working_dir": "${file_path}", 6 "selector": "source.c, source.c++", 7 8 "variants": 9 [ 10 { 11 "name": "Run", 12 //"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"] // Linux Only 13 "cmd": ["CMD", "/U", "/C", "g++ -std=c++11 ${file} -o ${file_base_name} && ${file_base_name}"] // For GCC On Windows Only 14 //"cmd": ["CMD", "/U", "/C", "CL /Fo${file_base_name} /O2 ${file} && ${file_base_name}"] // For CL On Windows Only 15 } 16 ] 17 }
然后保存,在保存文件对话框中把文件名字改成“C++11.sublime-build” 保存即可
然后选择Tools->Build System->C++11
这时你的Sublime Text就是一个完美的支持C++11的编辑器了!
相关文章推荐
- c++鼠标操作详解
- 从汇编层面深度剖析C++虚函数
- C++的64位整数[原]by 赤兔
- C++ 记事本: 从历史说起
- 也来说说C/C++里的volatile关键字
- c++ 遍历目录下文件
- C++学习之路—多态性与虚函数(二)纯虚函数与抽象类
- 深度探索C++对象模型:6.执行期语意学
- Eigen——线性代数运算的C++模板库
- 17行C语言程序耗尽系统的所有内存
- VC++6.0 显示Project代码行
- 《C语言实例解析精粹》(免费高速下载)pdf文档分享
- C++编程教程教你如何从零学起(免费高速下载)TXT文档分享
- 安卓之启动-初析(四)
- C++编程:Call Forwarding
- C/C++源码网站
- 【转】21天教你学会C++
- static关键字在c++中的运用
- 小记C++中switch....case的误用
- C++中生成int类型的最大值和最小值方法