String library or char* string?

What is better/more efficient and in what cases? String from the library or a char string (char*)?
When the size of a string is not changed it is better to use a character array.
Last edited on
string is always the default choice. I can't think of a realistic situation where a raw array of char would be an improvement, although, it's technically faster to create and destroy a function-local array than a default-allocated, sufficiently large, string object.

Now a string view/reference class can indeed be a good thing in real life.
Last edited on
Actually the best thing would be using string and cstring interchangeably. Cstrings have some decent string manipulation functions but string is safer and more practical to use. In some situations you would find it better to use one of these two, I find it particularly easy in string processing situations to stick with cstring, and I can easily convert back to the string.
Last edited on
If someone didn't understand me, with char strings I mean something like:

1
2
3
4
char* Spartan = "\n THIS...\n IS...\n SPARTAAAAA!\n\n";
cout << Spartan;
Spartan = "\n No;\n THIS IS PATRICK!!!\n\n";
cout << Spartan;


(Just a weird example)
Last edited on
If all you need is to reference a string literal, without manipulating its contents in any way, a pointer is sufficient (but do make it const char*, otherwise it's not a valid C++ program).
Topic archived. No new replies allowed.