如何让你的Sublime和Codeblocks支持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++ -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...
然后把下面的代码粘贴到新打开的文件中:
{
"cmd": ["g++", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"], // For GCC On Windows and Linux
//"cmd": ["CL", "/Fo${file_base_name}", "/O2", "${file}"], // For CL on Windows Only
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
//"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"] // Linux Only
"cmd": ["CMD", "/U", "/C", "g++ -std=c++11 ${file} -o ${file_base_name} && ${file_base_name}"] // For GCC On Windows Only
//"cmd": ["CMD", "/U", "/C", "CL /Fo${file_base_name} /O2 ${file} && ${file_base_name}"] // For CL On Windows Only
}
]
}
然后保存,在保存文件对话框中把文件名字改成“C++11.sublime-build” 保存即可
然后选择Tools->Build System->C++11
这时你的Sublime Text就是一个完美的支持C++11的编辑器了!

Chierush原创,转载请注明地址:http://www.cnblogs.com/Chierush/
如何让你的Sublime和Codeblocks支持C++11的更多相关文章
- Sublime和Codeblocks支持C++11
Sublime和Codeblocks支持C++11 闲来没事看了一下C++11,比起C++0x多了很多新功能,像auto变量,智能指针等,g++4.7以上版本也提供了对C++11的支持,但是,如何在你 ...
- Codeblocks支持C++11
Setting->Compiler 直接在“Have g++ follow the C++11 ISO C++ language standard [-std=c++11]” 选项上打勾 保存就 ...
- Sublime Text 3 支持的热门插件推荐
SublimeText是一款非常精巧的文本编辑器,适合编写代码.做笔记.写文章.它用户界面十分整洁,功能非同凡响,性能快得出奇.这些非常棒的特性 包括任意跳转(Goto Anything).多重选择( ...
- Sublime Text 3 支持的热门插件推荐(转载)
SublimeText是一款非常精巧的文本编辑器,适合编写代码.做笔记.写文章.它用户界面十分整洁,功能非同凡响,性能快得出奇.这些非常棒的特性 包括任意跳转(Goto Anything).多重选择( ...
- [转] Sublime Text 3支持GB2312和GBK编码
Sublime Text 3与Sublime Text 2的不同 其实有不少人写过如何让Sublime Text 2支持GB2312和GBK编码,例如这篇.基本原理就是先装好Package Contr ...
- Sublime codeIntel 配置支持php自动提示
Sublime codeIntel 配置支持php自动提示 下载地址:https://github.com/SublimeCodeIntel/SublimeCodeIntel 安装方法:下载后放到su ...
- 怎样让CodeBlocks支持C99
转载请注明出处,否则将追究法律责任http://blog.csdn.net/xingjiarong/article/details/47080303 CodeBlocks是一个写C/C++的比較好的编 ...
- mac上 sublime的配置,支持c++11且支持输入
首先下载mac版本的 sublimetext3 下载链接: https://www.sublimetext.com/3 接着可以按照其他博客的方法来安装一些插件,便于我们的工作和学习 安装sublim ...
- codeblocks不支持c++11的有效解决办法
首先cb支持c++11编程开发,但是不支持编译 看了网上好多,说setting里面设置一下就好了,16.01版本我安装了带ide的不带IDE的,安了好多次,但是就是没有那个选项 找不到c++11那个选 ...
随机推荐
- Method and Apparatus for Providing Highly-Scalable Network Storage for Well-Gridded Objects
An apparatus comprising a plurality of storage nodes comprising a plurality of corresponding storage ...
- Managing uniquely tagged items using the internet
The invention teaches managing an item in the Internet of Things, wherein the system comprises: an i ...
- “warning C4996: 'fopen': This function or variable may be unsafe”和“LINK : fatal error LNK1104”的解决办法
程序有时编译出现警告C4996,报错: warning C4996: 'fopen': This function or variable may be unsafe. Consider using ...
- Json格式日期转换为一般日期
Json日期转换为一般日期:json日期:/Date(1316756746000)/ 转换为2013-09-01格式的 1 //将json格式的时间转换成一般时间 2 function Chang ...
- C# WinForm 文件上传下载
/// <summary> /// WebClient上传文件至服务器 /// </summary> /// <param name="fileNamePath ...
- if-then和if-then-else声明
1.使用if-then声明 结构化命令,主要类型为if-then声明.if-then例如,下面的语句格式: if command then commands fi 假设你在使用其它编程语言的if-th ...
- Apache 配置 HTTPS访问
将需要配置的项目移动到另一根目录下,作为https访问位置. 修改bitnami配置文件..\Bitnami\wampstack-5.6.19-0\apache2\conf\bitnami\bitna ...
- maven_默认新建项目jdk1.6_默认配置
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...
- Symbol not found: _lua_objlen
lua: error loading module 'cjson' from file '/usr/local/lib/lua/5.3/cjson.so': dlopen(/usr/local/lib ...
- JS 数组两种定义方式
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...