I am trying to add some text values into an array such as
- some value 1
- some value 2
- some value 3
- etc..
here is the procedure i follow:
char values_array[3][80];
values_array[0][80] = "Rock and Rolla";
cout << values_array[0] << endl;
and i get the following error:
invalid conversion from `const char*' to `char'
The error message states exactly what the problem is. The assignment is attempting to assign a
const char*, the type of string string literal, to achar, the type ofvalues_array[0][80]. The incorrect immediate response would be change it to:but this is also incorrect as it is not possible to assign arrays. Either copy the string literal or, preferably, use a
std::vector<std::string>instead:Using a
std::vector<std::string>eliminates the hard-coded limit on the number of strings that can be stored and potential buffer-overrun problems when copying the string literals (or other strings) into the array elements.