预期的 ';'在声明结束时/vector/c++ [英] expected ';' at end of declaration /vector /c++

查看:30
本文介绍了预期的 ';'在声明结束时/vector/c++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 C++ 中初始化 int 向量时,我总是得到预期的 ';'在声明结束时"错误.

when I try to initialise a vector of int in c++, I always get the "expected ';' at end of declaration" error.

我使用了 C++ Primer 中的原始代码

I used the original code from C++ Primer

vector<int> v{1,2,3,4,5,6,7,8,9};

$ g++ -o test test.cpp

我认为这是一个愚蠢的问题,但我确信有一个;"......并且无法搜索答案..谢谢.

I think this is a silly question to ask, but I am sure that there is a ";"... and can not manage to search an answer.. Thanks.

推荐答案

g++ 默认采用 C++03,而您尝试使用的语法来自 C++11.将编译行改为:

g++ assumes C++03 by default, and the syntax you're trying to use came in C++11. Change the compilation line to:

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

或者,我个人更喜欢:

$ g++ -Wall -Werror -pedantic -std=c++1y -o test test.cpp 

:)

注意:您是使用 c++0xc++11 还是 c++1y(可能还有 c++14)主要取决于编译器版本,因为这些版本是后续引入的.

Note: whether you'd use c++0x, c++11, or c++1y (and possibly c++14) depends mostly on the compiler version, as those were introduced in succesion.

这篇关于预期的 ';'在声明结束时/vector/c++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆