首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >适当地将c++11添加到语法中

适当地将c++11添加到语法中
EN

Stack Overflow用户
提问于 2016-05-12 22:08:24
回答 1查看 1K关注 0票数 1

我知道在这方面已经存在的问题,但我不能通过评论来调查,因为我没有足够的声誉。

因此,我在vim中使用语法,并希望编译c++内容。

我的vimrc看起来是这样的:

代码语言:javascript
复制
 72 set statusline+=%#warningmsg#
 73 set statusline+=%{SyntasticStatuslineFlag()}
 74 set statusline+=%*
 75 
 76 " let g:syntastic_cpp_compiler = 'g++'
 77 let g:syntastic_cpp_compiler_options = ' -std=c++11'
 78 
 79 let g:syntastic_always_populate_loc_list = 1
 80 let g:syntastic_auto_loc_list = 1
 81 let g:syntastic_check_on_open = 1
 82 let g:syntastic_check_on_wq = 0

我的程序是这样的:

代码语言:javascript
复制
    1 #include <functional>
    2 
    3 using namespace std;
    4 
    5 int f(int x){
    6         return x;
    7 }
    8 
    9 void f2(function<int(int)> f){
   10 
   11 }
   12 
   13 int main(){
   14         return 0;
   15 }

如果我将vimrc中的第76行"clang++“替换为"g++”,则会得到以下错误:

代码语言:javascript
复制
  1 diff.cpp|11 col 6 error| variable has incomplete type 'void'                                        
  2 diff.cpp|11 col 11 error| use of undeclared identifier 'function'
  3 diff.cpp|11 col 33 error| expected '(' for function-style cast or type construction
  4 diff.cpp|11 col 46 error| expected '(' for function-style cast or type construction
  5 diff.cpp|11 col 48 error| expected ';' after top level declarator

如果我只需删除第77行并在其中使用g++进行编译,我就会得到:

代码语言:javascript
复制
  1 test.cpp|9 col 9 error| variable or field ‘f2’ declared void                                        
  2 test.cpp|9 col 9 error| ‘function’ was not declared in this scope
  3 test.cpp|9 col 18 error| expected primary-expression before ‘int’

最后,如果我像这里所看到的那样编译程序,我将完全没有语法检查。如果我然后编译,我会得到:

代码语言:javascript
复制
test.cpp:9:9: error: variable or field ‘f2’ declared void
 void f2(function<int(int)> f){
         ^
test.cpp:9:9: error: ‘function’ was not declared in this scope
test.cpp:9:18: error: expected primary-expression before ‘int’
 void f2(function<int(int)> f){

为什么是这样,我应该添加哪些检查器来简单地编译c++11文件?它真的令人沮丧

EN

回答 1

Stack Overflow用户

发布于 2018-06-24 06:44:17

设g:syntastic_cpp_compiler_options =‘-std=c++11’

在vimrc的第77行中有一个小错误。它应该是

代码语言:javascript
复制
let g:syntastic_cpp_compiler_options = ' --std=c++11'

注意std=c++11之前的两个破折号

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37198268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档