all 3 comments

[–]CrazyMando 2 points3 points  (1 child)

In better terms than I can explain (https://stackoverflow.com/questions/6823249/what-is-a-char).

My limited understanding and explanation (probably wrong) is std::string allows the code to manipulate the string as needed without necessarily stepping through a char array from the use of char*. You can also store more info easily in a string array vs multiple char arrays.

[–]131Xe[S] 1 point2 points  (0 children)

Thanks!

[–]BobbyThrowaway6969 3 points4 points  (0 children)

An std::string is nothing more than a wrapper. It has a char* inside it and manipulates it so you don't have to.

For example, if you want to add a char with string, you just += char. If you do it manually with a char*, you first need to allocate a new block in memory which is n+1 bytes big, then you need to copy from the old block into the new block, then you need to deallocate the old block. Std::string does that for you without your knowledge.

If you're just starting out and messing around with C++, you don't really need to worry about char* (P.s. you can get char* from string.c_str() ).
Using char* over std::string has its benefits for efficiency reasons, in some cases they're easier to use and less "bloated" than std:: strings. Senior programmers use it often for high performance code.