Iterators

begin:

end:

rbegin:

rend:

cbegin:

cend:

crbegin:

crend:

Capacity

size:

length:

max_size:

resize:

capacity: 返回实际分配的存储空间的大小,一般大于等于 size 。这样能优化插入等需要重新分配存储空间的操作。

reserve:

clear:

empty:

shrink_to_fit(c++11):

Element access

operator [ ]:

at:

back(c++11):

front(c++11):

Modifiers

assign:

operator +=:

append:

push_back:

insert:

erase:

replace:

swap:

pop_back(c++11):

String operations

c_str:

 1 // strings and c-strings
 2 #include <iostream>
 3 #include <cstring>
 4 #include <string>
 5 
 6 int main ()
 7 {
 8   std::string str ("Please split this sentence into tokens");
 9 
10   char * cstr = new char [str.length()+1];
11   std::strcpy (cstr, str.c_str());
12 
13   // cstr now contains a c-string copy of str
14 
15   char * p = std::strtok (cstr," ");
16   while (p!=0)
17   {
18     std::cout << p << '\n';
19     p = std::strtok(NULL," ");
20   }
21 
22   delete[] cstr;
23   return 0;
24 }
View Code

相关文章:

  • 2021-08-14
  • 2021-09-04
  • 2021-08-23
  • 2022-01-23
  • 2021-10-05
猜你喜欢
  • 2021-06-06
  • 2022-01-31
  • 2022-01-04
  • 2021-09-17
  • 2021-12-17
相关资源
相似解决方案