String

  1. size/length: int n = s.size();
  2. find: find char in string s.find(ch) return pos; return string::npos or -1 if not found
  3. swap: s1.swap(s2) swap string s1 and s2; swap(s[1], s[2]) swap char in string pos 1 and 2;
  4. erase: s.erase(a,b); or s.erase(s.begin()+a, s.end());
  5. s.push_back(ch); insert, s.pop_back() erase last.
  6. s.c_str(): return a constant, non-modifiable string
  7. str.substr(i, k); extract substr of size k from pos i;
  8. to_string(num): int to str; stoi(str);: str to int;
  9. str to int: atoi(str.c_str());, leading whitespace will be ignored, negative number ok, wrong expression will be transfered to 0. stoi : throw error instead of giving 0;