C ++ / STL: 2-container-String

------String------

What is String

  • String is a class that exists specifically for string manipulation in C ++. String encapsulates char *, and manage this string, can be understood as a char * type container.

Compared

  • Both string and char * can represent a string.
  • For char *, it is a pointer to the first address of the character array. After declaring a string, if you want to manipulate it, you must introduce the C-style string header file include <string.h> . The <string.h> header file encapsulates strlen , strcat , strcpy , strcmp and other functions. Use them to perform related operations on the declared string.
  • String is a class that encapsulates the above content together, making string operations more flexible, more ways, and more reasonable management.
  • When using the string class, we need not consider the allocation and deallocation of memory , but also do not have to worry about cross-border collapse , basically everywhere to consider their predecessors have done, we just use on the line. This is a big advantage compared to char * used with string.h .
Published 16 original articles · praised 7 · 20,000+ views

Guess you like

Origin blog.csdn.net/yuecangjiao5151/article/details/103452984