When should I use std::string and when should I use char* to manage arrays of chars in C++?
It seems you should use char* if performance(speed) is crucial and you’re willing to accept some of a risky business because of the memory management.
Are there other scenarios to consider?
You can pass
std::strings by reference if they are large to avoid copying, or a pointer to the instance, so I don’t see any real advantage usingcharpointers.I use
std::string/wstringfor more or less everything that is actual text.char *is useful for other types of data though and you can be sure it gets deallocated like it should. Otherwisestd::vector<char>is the way to go.There are probably exceptions to all of this.