-3

i have a sample C++ code - So that give me a Warning with this content : [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11 how i can solve that ?

This is my code :

#include <iostream>
using namespace std;
struct CandyBar
{
 const  char Brand[255];
  float Weight;
  int Calories;
};
  CandyBar Snake{"Mocha Munch",2.3,350};

int main()
{
  cout << Snake.Brand << endl;
  cout << Snake.Weight << endl;
  cout << Snake.Calories << endl;
  return 0;
}
drescherjm
  • 9,653
  • 5
  • 43
  • 62
mohamadami
  • 13
  • 7

1 Answers1

2

The error message tells you what to do.

You're trying to use a C++11 feature, so enable C++11 mode by passing -std=c++11 to your compiler. If you're using some build system instead of just calling g++ on the command-line, read its documentation to find out how to achieve this.

Or you could upgrade your compiler, because C++11 or even C++14 is the default in more up-to-date versions.

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021