Why use c strings in c++?

后端 未结 18 2134
终归单人心
终归单人心 2021-02-07 04:12

Is there any good reason to use C-strings in C++ nowadays? My textbook uses them in examples at some points, and I really feel like it would be easier just to use a std::string

18条回答
  •  清酒与你
    2021-02-07 04:48

    It depends on the libraries you're using. For example, when working with the MFC, it's often easier to use CString when working with various parts of the Windows API. It also seems to perform better than std::string in Win32 applications.

    However, std::string is part of the C++ standard, so if you want better portability, go with std::string.

提交回复
热议问题