Summary of the use of string in C++

God is weak

C + + string array

Abstract: The function and use method of string class in C++ can be analogous to the character array in C language, but compared with each other it can be said to be worse, it is too convenient, so leave this post to summarize the experience of daily learning. Create string s and assign string s = “Hello,World!” ; String s (” Hello, World!” ); Assignment and tuning.

The function and use method of string class in C++ can be analogous to the character array in C language, but compared with each other, it is too convenient, so I leave this post to summarize the experience gained from daily learning.

Retarded blog, typesetting so difficult?? ? 1. Create string s and assign a value

string s = "Hello,World!" ; String s (" Hello, World!" );Copy the code
  1. Assignment and callstring s; cin >> s; // Assign the character array cout << s; Cout << s[I]; // Prints the I +1 character

    3. Use of +, -, =, <, >, <=, >= in string
string s1 = "12345"; string s2 = "67890"; If (s1==s2) cout<<"s1 =s2 "<<endl; If (s1>=s2) cout<<"s1 string length is greater than or equal to s2"<<endl; cout<<s1+s2<<endl; // Print "1234567890" cout<<s1-s2<<endl; / / output "1234567890"Copy the code

[email protected]

Use the cloud habitat community APP, comfortable ~

For details, please click
Review articles (0)

Related articles

The net friend comment on