1. Historical legacy issues and Solutions
(1) problems left over from history
①C language does not support strings in the real sense
②c language implements string manipulation with character arrays and a set of functions
③c language does not support custom types, so string types cannot be obtained
(2) Solutions
① the evolutionary process from C to C + + introduces a custom type
② the definition of a string type in C + + through a class
2. string classes in the standard library
(1) C + + directly supports all concepts
(2) There is no original string type in the C + + language
(3) C + + standard library provides string types (support for string connections, size comparisons, substring lookups and extractions, string insertions and substitutions, and so on)
Use of the "programming Experiment" string class
3. string classes in the standard library
(1) String Stream class: (<sstream> header file)
①istringstream: String input stream
②ostringstream: String Output stream
(2) conversion of strings to numbers
string→ Digital |
Digital →string |
Istringstream ISS ("123.45"); Double num; iss>>num; |
Ostringstream OSS; oss<<543.21; string s = Oss.str (); |
Conversion of "programming experiment" strings and numbers
(3) Related operations of the String class
① Precautions:
A. #include <string>. Note, not <string.h>.
B. is divided into string and wstring versions. corresponding to char and wchar_t, respectively
C. Using std::string; or using std::wstring;
Related operations of the ②string class (click here for links)
"Programming Experiment" completes the loop shift of strings in C + +
4. Summary
(1) Most of the situations in application development are string processing
(2) There is no direct support for native string types in C + +
(3) The concept of string support in the standard library
(4) String class supports mutual conversion of strings and numbers
(5) The application of the string class makes the problem easier to solve
33rd lesson the string in C + +