String Class Related Program [leetcode]

String is the best study programmers coding a basic point, but more error-prone points, the following is more error-prone coding in place.

  1. When a character string to be accessed, then the character to be added to another array, specify the length of a note, or both the entire string will go copy
string s1 = "123";
string s2 = "";
char c = s1.at(0);
s2 += string(&c, 1);
  1. In processing the input and output, although you can use the input-output method c language form, but since c ++ already provides such a good class, stop using c language in the form of input, such as the console can get his string use:
string inputs;
getline(cin, inputs);
  1. Conversion case letters, English letters are in fact 26, but since there are several special symbols, resulting in lower-case is in fact the size of the turn table 32 may be so asci C = c + '32', if the fear of wrong, can Thus C = c + 'A' - 'a';
Published 36 original articles · won praise 3 · views 10000 +

Guess you like

Origin blog.csdn.net/wang_jun_whu/article/details/103999976