Dynamic character array in C++ initialized with C-style string

Viewed 33

I'm trying to allocate a dynamic array and initialize it with the content "Hello World". The code is as below.

char *text = new char[]{"Hello World"};

This works perfectly in Visual C++, but throws the below errors in gcc.

test.cc:3:24: error: expected primary-expression before ‘]’ token
  char *text = new char[]{"Hello World"};
                        ^
test.cc:3:39: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
  char *text = new char[]{"Hello World"};
                                       ^

Need help with the following questions.

  1. Is there any known defect in gcc?
  2. Shouldn't it work as per the standard?
  3. Is Visual C++ Compiler going out of its way to support this?
  4. Should this be done differently in gcc?
0 Answers
Related