C++ self-learning notes(5)

In this note I'll first introduce some operation to the system clock and then I'll share some information about string operations.

1. Time

head files, I recently learnt two useful head files about system clock and time format. A) <chrono> and B) <time.h>. For the specific, see the example below:

190221_DaQT_2968040.png

the result is:

190512_lJaS_2968040.png

Important points here is: time_point and time_t classes have different formats, and you can use the function: to_time_t to convert the format from time_point to time_t. There is also from_time_t to do the inverse conversion. 

Another important function in the example is ctime_s. It requires three input parameters: 

1) a vector that stores the time information; 2) the size of the vector; 3) the pointer pointing to the variable contains the time information in a time_t format.

Useful links:

http://www.cplusplus.com/reference/chrono/time_point/

http://www.cplusplus.com/reference/chrono/system_clock/to_time_t/

http://www.cplusplus.com/reference/chrono/system_clock/now/

http://www.cplusplus.com/reference/chrono/system_clock/from_time_t/

 

2. String

First I'm going to introduce the class ostringstream. Ostringstream is a keyword defined by standard namespace and included in the header <sstream>.  The class ostringstream uses a string buffer to store a sequence of characters which can be accessed using the string object(_.str).

194816_ikhy_2968040.png

result:

195001_GJyK_2968040.png

 

There is also istringstream and stringstream, you can find more information 

here: http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html

 

Useful link:

http://www.cplusplus.com/reference/sstream/ostringstream/

http://blog.csdn.net/qq1987924/article/details/7671154

 

 

转载于:https://my.oschina.net/u/2968040/blog/995713

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值