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

后端 未结 12 1181
北海茫月
北海茫月 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:43

    The only time I've recently used a C-style char string in a C++ program was on a project that needed to make use of two C libraries that (of course) used C strings exclusively. Converting back and forth between the two string types made the code really convoluted.

    I also had to do some manipulation on the strings that's actually kind of awkward to do with std::string, but I wouldn't have considered that a good reason to use C strings in the absence of the above constraint.

提交回复
热议问题