简体   繁体   English

错误:预期为';' 在“ <”令牌之前

[英]error: expected ';' before '<' token

my compiler throws 我的编译器抛出

error: expected ';' before '<' token

on this line of code: 在这行代码上:

std::vector< std::vector<int> > data;

What's real weird is that I compiled this earlier today on my mac with g++ on the command line and now i'm trying to compile in xCode on the same mac (which i assume also uses g++) and it throws this error. 真正的怪异之处是,我今天早些时候在Mac上使用g ++在命令行上对此进行了编译,现在我试图在同一Mac上的xCode中进行编译(我假设也使用g ++),并且抛出此错误。

What am I missing here? 我在这里想念什么?

EDIT: I knew it had to be right in front of me, but there was nothing else wrong in the file. 编辑:我知道它必须在我面前,但文件中没有其他错误。 it was the semicolon at the end of an included class. 它是包含类末尾的分号。 Thanks. 谢谢。

Probably you are missing a semicolon at the end of what's on the previous line. 可能您在上一行的末尾缺少分号。

If you have no code before that line, then it is a missing semicolon at the end of one of your included header files. 如果在该行之前没有代码,则在包含的头文件之一的末尾缺少分号。

For example you can reproduce this error using: 例如,您可以使用以下方法重现此错误:

#include <vector>
class C
{

}

std::vector< std::vector<int> > data;

Possibly #include <vector>, or possibly something is wrong in the code that comes before that line. 可能#include <vector>,或者在该行之前的代码中有错误。 It is very difficult to say without seeing the entire code. 如果不看完整的代码,很难说。

Try #include <vector> . 尝试#include <vector> Different compilers or versions of the same compiler do different things with the STL includes. 对于STL包含,不同的编译器或同一编译器的版本会做不同的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM