33rd lesson the string in C + +

Source: Internet
Author: User

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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.