1、统计程序运行时间
#include <sys/time.h>
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);
sleep(5);
gettimeofday(&end_time, NULL);
//cost_time的单位是微秒
long cost_time = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec);
std::cout << "total cost time : " << cost_time/1000000 << endl;
return 0;
}
2、分割字串函数
// 对字符串根据指定的单个字符进行拆分,返回分割后的字符串数组
vector<string> SplitString(const string& obj_string, char character)
{
vector<string> string_vector;
if (obj_string.size() == 0)
{
return string_vector;
}
size_t pos_begin = 0;
size_t pos_end = 0;
bool last_obj_store = true;
while (pos_end != string::npos)
{
pos_begin =