char* vs std::string in c++

anon picture anon · Apr 29, 2009 · Viewed 75.1k times · Source

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?

Answer

Gal Goldman picture Gal Goldman · Apr 29, 2009

My point of view is:

  • Never use char * if you don't call "C" code.
  • Always use std::string: It's easier, it's more friendly, it's optimized, it's standard, it will prevent you from having bugs, it's been checked and proven to work.