浠ユ妧鏈负涓
stl
std涓簩鍒嗘煡鎵惧嚱鏁伴泦鍚
鍏 9th
1,binary_search()聽 鐢ㄦ硶锛歨ttp://www.sgi.com/tech/stl/binary_search.html
2,lower_bound()聽聽 鐢ㄦ硶锛歨ttp://www.sgi.com/tech/stl/lower_bound.html
3,upper_bound() 鐢ㄦ硶锛歨ttp://www.sgi.com/tech/stl/upper_bound.html
4,equal_range()聽 鐢ㄦ硶锛歨ttp://www.sgi.com/tech/stl/equal_range.html
STL浣跨敤鎬荤粨涔媣ector,map
鍗佷竴 22nd
鏈杩戝湪鍋歞ata mining鐨勪綔涓欰priori绠楁硶鐨勫疄鐜版槸鐢ㄥ埌STL鐨勭煡璇嗭紝鍥犱负涔嬪墠骞舵湭绯荤粺鍦扮敤杩嘢TL搴擄紝鎵浠ュ湪鍐欑▼搴忔椂锛岄亣鍒颁簡寰堝闂锛屼粖澶╂荤粨涓嬶紝浠ヤ究浠ュ悗瀵筍TL鏈夋洿濂界殑浣跨敤
銆
绋嬪簭涓富瑕佺敤鍒颁袱绉嶆暟鎹粨鏋勶細vector,map
涓锛寁ector浠嬬粛
<1>绠鍗曞湴璇达紝vector鏄竴涓兘澶熷瓨鏀句换鎰忕被鍨嬬殑鍔ㄦ佹暟缁勶紝鑳藉澧炲姞鍜屽垹闄ゆ暟鎹
<2>瀹氫箟鏂规硶锛歷ector<string> myvector;
<3>鎻掑叆璁板綍锛
1锛宲ush_back(const T&);娉ㄦ剰push_back()鐨勫弬鏁版槸寮曠敤绫诲瀷鐨勶紝鍒氬紑濮嬫垜浠ヤ负鍦╲ector涓彃鍏ユ暟鎹彧鏄彃鍏ヤ竴鏉¤褰曠殑寮曠敤锛屽苟鏈鍒惰璁板綍鐨勫疄闄呭硷紝鍚庢潵鎵嶇煡閬撲笉鏄繖鏍
鐨勶紝vector閲嶆柊涓篢寮杈熶簡涓娈靛唴瀛樼┖闂达紝鑷充簬涓轰粈涔堝弬鏁版槸寮曠敤绫诲瀷锛屾垜涔熶笉澶竻妤氥傛渶甯哥敤
2锛宮yvector[2] = “mystring”;鍒╃敤[]鎻掑叆涓鏉¤褰曘
3锛宨terator insert(iterator pos,const T& x)聽 //娌℃庝箞鐢ㄨ繃
void insert(iterator pos,InputIterator f, InputIterator l)
void insert(iterator pos, size_type n, const T& x)
<4>璁块棶璁板綍锛 鏇村 >
涓篠TL涓殑std::string娣诲姞trim鍑芥暟鐨勫疄鐜
鍗佷竴 14th
浠g爜濡備笅锛
//鑷畾涔塼rim鍑芥暟
string trim(string& str)
{
string::size_type pos = str.find_last_not_of(‘ ‘);
if(pos != string::npos)
{
str.erase(pos + 1);
pos = str.find_first_not_of(‘ ‘);
if(pos != string::npos) str.erase(0, pos);
}
else str.erase(str.begin(), str.end());
return str;
std::string鐨剆plit鍑芥暟鐨勮嚜瀹氫箟瀹炵幇
鍗佷竴 14th
std::string涓湭瀹氫箟split鍑芥暟锛岀綉涓婃壘鍒颁竴绉嶆柟娉曞疄鐜帮紝鍒嗕韩涔
//鑷畾涔夊疄鐜皊plit鍑芥暟
void split(std::string& s, std::string& delim,std::vector< std::string >* ret)
{
size_t last = 0;
size_t index=s.find_first_of(delim,last);
while (index!=std::string::npos)
{
string tt = s.substr(last,index-last);
tt.
ret->push_back();
last=index+1;
index=s.find_first_of(delim,last);
}
if (index-last>0)
{
ret->push_back(s.substr(last,index-last));
}
}
杩戞湡璇勮