有哪些鲜为人知却又很好用的 STL 函数?
链接:https://www.zhihu.com/question/270085840/answer/352317215
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
数字转字符串:
string s = to_string( num);
字符串转数字:
int i = stoi( str);
long l = stol( str);
double d =stod( str);
……等
名称 原型 说明
stoi int stoi (const string& str, size_t* idx = 0, int base = 10);
int stoi (const wstring& str, size_t* idx = 0, int base = 10); Convert string to integer (function template )
stol long stol (const string& str, size_t* idx = 0, int base = 10);
long stol (const wstring& str, size_t* idx = 0, int base = 10); Convert string to long int (function template)
stoul unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10); Convert string to unsigned integer (function template)
stoll long long stoll (const string& str, size_t* idx = 0, int base = 10);
long long stoll (const wstring& str, size_t* idx = 0, int base = 10); Convert string to long long (function template)
stoull unsigned long long stoull (const string& str, size_t* idx = 0, int base = 10);
unsigned long long stoull (const wstring& str, size_t* idx = 0, int base = 10); Convert string to unsigned long long (function template)
stof float stof (const string& str, size_t* idx = 0);
float stof (const wstring& str, size_t* idx = 0); Convert string to float (function template )
stod double stod (const string& str, size_t* idx = 0);
double stod (const wstring& str, size_t* idx = 0); Convert string to double (function template )
stold long double stold (const string& str, size_t* idx = 0);
long double stold (const wstring& str, size_t* idx = 0); Convert string to long double (function template)
可能不算鲜为人知吧……毕竟stl没几个……
inplace_merge,写分治的时候很好用
nth_element,写暴力的时候很好用
stable_sort,sort的时候可以少记录一维,虽然用了pair也就是两行的事……
make_heap,唔,我记得这个东西我只用过一次?
S.erase(unique(S.begin(), S.end()), S.end()) 去重小技巧
作者:3and2and1
链接:https://www.zhihu.com/question/270085840/answer/352040460
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
可能不算鲜为人知吧……毕竟stl没几个……
inplace_merge,写分治的时候很好用
nth_element,写暴力的时候很好用
stable_sort,sort的时候可以少记录一维,虽然用了pair也就是两行的事……
make_heap,唔,我记得这个东西我只用过一次?
S.erase(unique(S.begin(), S.end()), S.end()) 去重小技巧
作者:3and2and1
链接:https://www.zhihu.com/question/270085840/answer/352040460
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
