c++initializationatom-editorcurly-braces

Unexpected result when initializing variable in C++ using curly braces


I'm using atom to practice C++ (I'm very new). I just learned to initialize variables like the following:

#include <iostream>

using namespace std;

int main() {

  int myInt {};
  
  return 0;
}

When I build and run the previous code in codelite I receive no errors. However, if I compile my atom file dailyPractice10.cpp using my MacBook terminal (zsh) I get the following error:

dailyPractice10.cpp:7:12: error: expected ';' at end of declaration
int myInt {};
        ^
        ;
1 error generated.

I'm using the following command to compile it on terminal:

g++ -o dailyPractice10 dailyPractice10.cpp (compiles)

./dailyPractice10 (runs program)

Does anyone have any feedback why this code runs in codelite but doesn't compile in terminal?


Solution

  • Because this feature is added from c++11.

    if you will like to try below command.it will work.

    $ g++ -std=c++0x -o dailyPractice10 dailyPractice10.cpp