VP Lex
VP Lex

Reputation: 49

Error while declaring int variable using curly braces in g++

I compiled this code using g++ and got an error:

#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.

Upvotes: 0

Views: 75

Answers (1)

BartekPL
BartekPL

Reputation: 2430

You have probably used an old version of compiler .

On Godbolt, I have checked that it may be older than 4.4.7.

You may have to add -std=c++11 flag to compile.

Newer compiler has this standard enable as default.

Upvotes: 1

Related Questions