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

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

    In all my professional career I've had an opportunity to use std::string at only two projects. All others had their own string classes :)

    Having said that, for new code I generally use std::string when I can, except for module boundaries (functions exported by dlls/shared libraries) where I tend to expose C interface and stay away from C++ types and issues with binary incompatibilities between compilers and std library implementations.

提交回复
热议问题