使用C++11中的遍历工具

处理日期和时间的chromo库

duration表示一段时间间隔,表示几秒、几分钟等。

typedef duration<Rep, ratio<60,1>>  minutes;
typedef duration<Rep, ratio<1,1>>  seconeds;
typedef duration<Rep, ratio<1,1000>>  milliseconds;

Rep表示时间数值,ratio表示时钟周期。ratio<60,1>表示一个时钟周期是60秒。
通过定义这些常用的时间间隔,我们可以方便的直接使用:

this_thread::sleep_for(chrono::seconds(3)); //休眠3秒钟

时间间隔之间的计算

    chrono::minutes t1(10);
    chrono::seconds t2(60);
    chrono::seconds t3 = t1 - t2;
    cout << t3.count() << " seconds" << endl;

输出结果为540秒。

数值类型和字符串的相互转化

    double f = 1.53;
    string fstring = to_string(f);
    cout << fstring << endl;
atoi: 将字符串转化为int
atol: long
atoll: long long
atof: float

示例代码:

    const char* str1 = "10";
    cout << atoi(str1) << endl;

    const char* str2 = "3.15144";
    cout << atoi(str2) << endl;
    cout << atof(str2) << endl;

    const char* str3 = "31222 with words";
    cout << atoi(str3) << endl;
    cout << atof(str3) << endl;

    const char* str4 = "begin 31222 with words";
    cout << atoi(str4) << endl;
    cout << atof(str4) << endl;

输出:

10
3
3.15144
31222
31222
0
0
请按任意键继续. . .
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值