【C++語法】STL
阿新 • • 發佈:2021-08-09
Container
Built-in Types | Abstract Data Types |
---|---|
defined directly by C++ language | defined by standard libraty |
repersents computer hardware facilities | usually don't implemented by computer hardware |
e.g., int, array... | e.g., vector, string... |
String
std::string::npos //-1 /*初始化*/ string s(10, 'c'); //s: "cccccccccc" /*遍歷*/ for(auto &c:s) //&引用 /*normal*/ s.size(); s.empty(); /*find*/ s.find(substr, pos=0); //return size_type /*子串*/ s.substr(pos,count); //return string /*string, char [], char**/ ... /*string,int*/ to_string((int)i); //<string> /*Algorithms*/ reverse(s.begin(),s.end());
1. vector
/*Algorithms*/
vector<int>::iterator max = max_element(v.begin(),v.end());
reverse(v.begin(),v.end());
sort(v.begin(),v.end(),cmp()=NULL);
stable_sort(v.begin(),v.end(),cmp()=NULL);
from Chu