sort简单使用 struct Record {
string name;
// ...
};
struct name_compare { // compare Records using "name" as the key
bool operator()(const Record& a, const Record& b) const
{ return a.name<b.name; }
};
void f(vector<Record>& vs)
{
sort(vs.begin(), vs.end(), name_compare());
// ...
}
|
delete后自动赋值为0的模板函数 template<class T> inline void destroy(T*& p) { delete p; p = 0; }
|
整数转字符串 #include<iostream>
#include<string>
#include<sstream>
using namespace std;
string itos(int i) // convert int to string
{
stringstream s;
s << i;
return s.str();
}
int main()
{
int i = 127;
string ss = itos(i);
const char* p = ss.c_str();
cout << ss << " " << p << "\n";
}
|
| 以上代码来自网上以及自己编写 |
本文出自 “Never Stop Sharing” 博客,请务必保留此出处http://loma1990.blog.51cto.com/6082839/1391831
原文:http://loma1990.blog.51cto.com/6082839/1391831