C++的常用轮子

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 =
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值