How do I initialize a c-string in C++11?
I tried:
char* foo = {"bar"};
but I get:
ISO C++11 does not allow conversion from string literal to 'char *
How do I initialize a c-string in C++11?
I tried:
char* foo = {"bar"};
but I get:
ISO C++11 does not allow conversion from string literal to 'char *
Because it has to be pointer to const
:
const char* foo = "bar";
Before C++11, you could make foo
simply char*
, even though that was deprecated since C++03. But C++11 removes the deprecation and simply makes it illegal.
The correct way to do it is;
char const* foo = {"bar"};
// ^^^^^ added const
The older C style (non const
) was deprecated and now is removed from C++11.