char and <string>
I'm taught (from the book that i read) that there are two ways to work with strings. Either use an array of char s or use functions inside header file <string>. Although the book introduced the 2 together, it took way more pages convincing me that <string> is the better way to do it. Any ideas on why you would and you would NOT use <string>? Cuz I see many posts in this forum that still uses char arrays.
The best thing about the std::string class (from <string>) is that you do not have to worry about the memory allocation/deallocation with it. It handles that for you, and consequently, it is much more safe.
There is less overhead with directly manipulating character arrays, than dealing with the string object itself, but this is usually of minimal importance, so std::string is the preferred way to go.
People worked with character arrays for many years, in C and in C++. Invariably this meant writing various functions to perform useful tasks with these arrays, in addition to those provided in <string.h>.
In C++ it was common for people to write their own string classes, with this level of functionality included. The content of these classes would, of course, vary depending on who wrote them and what functionality they required.
The C++ standard library has conveniently provided such a string class for you, so you don't need to write your own. The version that ships with your favourite compiler will have been written, tested and debugged, and by now used by thousands of programmers in probably millions of lines of code.
Because it's part of the standard library, as defined by the C++ standard, you can rely on the std::string class being available on any (relatively) standard conforming compiler. Once you're familiar with it, you can change compilers, change OS, change employer, and still code the same. You can work with other people knowing that when they handle strings using the standard library you'll be able to understand their code.
The std::string class doesn't do everything. If you need something that it doesn't provide, go ahead and write your own. Or use character arrays. But for most purposes, you'll probably find using a portable standard library class to be of benefit.