C++ strings connecting with char arrays

arrays, c++, char, string

Solution

I would write:

string str = string(array) + array2;

Note that your second version is not valid code. You should remove the parentheses:

string str;
str += array;
str += array2;

Lastly, `array` and `array2` should be of type `const``char *`.

Problem

Is this good way to do it? ``` char* array = "blah blah"; char* array2 = "bloh bloh"; string str = string() + array + array2; ``` Can't do direct `string str = array + array2`, can't add 2 pointers. Or should I do this ``` string str(); str += array; str += array2; ```

Original source

Related problems