Why do you prefer char* instead of string, in C++?

后端 未结 12 1199
北海茫月
北海茫月 2021-02-01 08:31

I\'m a C programmer trying to write c++ code. I heard string in C++ was better than char* in terms of security, performance, etc, however sometimes it

12条回答
  •  花落未央
    2021-02-01 08:45

    Implementations of std::string hide the memory usage from you. If you're writing performance-critical code, or you actually have to worry about memory fragmentation, then using char* can save you a lot of headaches.

    For anything else though, the fact that std::string hides all of this from you makes it so much more usable.

提交回复
热议问题