Chapter three string, vector and array
Name space
Using Std::cin;
using namespace Std;
String S4 (3, ' C '); The value of S4 is "CCC"
Use Getline to read a whole line
String line;
Getline (cin, line);
If a row is successfully read, the Getline function returns True (reading to a blank line also returns True, because the read succeeded to a ' \ n '), where line is an empty string, and the read failure returns false.
Getline reads the newline character, and the newline character is also read in, but the newline character is not stored when the string is stored in an object.
Action on a String object
Os<<s writes s to output stream OS, returns OS
Is>>s reads the string from input stream is to S, returns is
Getline (IS, s) reads a row from an input stream is assigned to s
S.empty ()
S.size () s.length () There's no difference.
S[i]
+
=, = =,! =
<, <=, >, >=
The size function return type of string is the Size_type type, which is an unsigned integer.
string S ("abc"); The S.size () value is 3, note that it is an unsigned number
BOOL B1 = S.size () <-1; The value of B1 is true, because S.size () is an unsigned number, and when mixed with signed and unsigned numbers, the signed number is automatically converted to an unsigned number, where 1 becomes a large positive integer (the way the conversion is discussed in the 2nd chapter)
int len = S.size (); Unsigned number s.size () first converted to a signed number Len
bool B2 = Len <-1; The value of B2 is false, because Len is a signed number, and an unexpected auto-conversion problem occurs when there is no signed and unsigned number mixed with the 1 comparison
Dictionary order size Comparison of strings
The comparison result of the string size equals the first pair of distinct characters
"ABC" < "AC"
If the corresponding position characters are all the same, the smaller string size is small
"ABC" < "ABCD"
Otherwise two strings are equal
Tips for C + + Primer Chapter 3