简体   繁体   English

在G ++中使用花括号声明int变量时出错

[英]Error while declaring int variable using curly braces in g++

I compiled this code using g++ and got an error: 我使用g ++编译了此代码,但出现错误:

#include<iostream>
using namespace std;
int main()
{
    int j{ 0 };
    cout << "j = " << j << endl;
    return 0;
}

This is the error: 这是错误:

error: expected ';' at end of declaration
    int j{ 0 };
         ^
         ;
1 error generated.

You have probably used an old version of compiler . 您可能使用了旧版本的编译器。

On Godbolt , I have checked that it may be older than 4.4.7. Godbolt上 ,我检查了它可能早于4.4.7。

You may have to add -std=c++11 flag to compile. 您可能必须添加-std=c++11标志才能进行编译。

Newer compiler has this standard enable as default. 较新的编译器默认启用此标准。

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

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