How to get the number of characters in a std::string?

前端 未结 12 991
既然无缘
既然无缘 2020-11-28 03:52

How should I get the number of characters in a string in C++?

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 04:34

    If you're using old, C-style string instead of the newer, STL-style strings, there's the strlen function in the C run time library:

    const char* p = "Hello";
    size_t n = strlen(p);
    

提交回复
热议问题