Gvim自动编译运行c++11的程序

  gcc中对c++11的支持是默认不开启的,要想在实现对其的成功编译,需要添加参数-std=c++11:

g++ -o test.exe test.cpp

g++ -o test.exe test.cpp -std=c++11

即上述代码中第二行才能实现对c++11代码的成功编译;

  要在Gvim中自动编译运行c++11的 .cpp 程序需要在_vimrc文件中添加如下代码:

" <F5> 编译和运行C/C++

map <F5> :call CompileRunGcc()<CR>

func CompileRunGcc()

    exec "w"

        if &filetype == 'c'

			echo "Compiling ..."

		    exec "!gcc % -o %<"

            echo "Compiled successfully ..."

		    exec "! %<"

	    elseif &filetype == 'cpp'

			echo "Compiling ..."

		    exec "!g++ % -o %< -std=c++11"

			echo "Compiled successfully ..."

		    exec "! %<"

        endif

endfunc

  附上一篇介绍各种编译器对c++11标准的的支持情况:

  http://www.tuicool.com/articles/bAzeay

你可能感兴趣的:(C++)