Prefer std::string to char*

This is the title of my last article published on CodeGuru, http://www.codeguru.com/cpp/cpp/string/general/article.php/c13267/. Being active on forums like CodeGuru or MSDN I’ve seen so many times people using char* in places where a std::string would have made their life much easier. This is an error usually made by people coming from a C background, or those who learn C++ from books with titles like “Everything about C/C++”, books that teach C++ in the C way. I’m totally against that. C++ is not just C with classes.

std::string being a type from STL, offers support for copying and assigning,operations such as comparison or concatenation, iteration, use of STL algorithms,etc. Using it makes your code more natural, more easier to read and maintain.

Please feel free to add any comment on the topic or the content of the article.

Posted in:

1 Comment on "Prefer std::string to char*"

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.