zoukankan      html  css  js  c++  java
  • Sublime和Codeblocks支持C++11

    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++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的编辑器了!

    Chierush原创,转载请注明地址:http://www.cnblogs.com/Chierush/

     
     
     
    标签: C++11Sublime
  • 相关阅读:
    网络-基础知识
    手机开发-安卓手机的更新换代
    C-基础
    手机开发-IOS
    前端- html 和css
    jmeter接口测试-文件下载
    JDBC接口
    jmeter接口测试实例7-关联
    jmeter接口测试实例6-注册(参数化)
    jmeter接口测试实例5-文件上传
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3318129.html
Copyright © 2011-2022 走看看