Why should one use std::string over c-style strings in C++?

后端 未结 6 2032
慢半拍i
慢半拍i 2020-12-15 23:36

\"One should always use std::string over c-style strings(char *)\" is advice that comes up for almost every source code posted here. While the

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 00:17

    3) The advice always use string of course must be taken with a pinch of common sense. String literals are const char[], and if you pass a literal to a function that takes a const char* (for example std::ifstream::open()) there's absolutely no point wrapping it in std::string.

提交回复
热议问题