c++笔记

system()

相关函数:fork, execve, waitpid, popen头文件:#include <stdlib.h>定义函数:int system(const char * string);
system(“pause”)可以实现冻结屏幕,便于观察程序的执行结果;system(“CLS”)可以实现清屏操作。而调用color函数可以改变控制台的前景色和背景,具体参数在下面说明。
例如,用 system(“color 0A”); 其中color后面的0是背景色代号,A是前景色代号。各颜色代码如下:
0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色 6=黄色 7=白色 8=灰色 9=淡蓝色 A=淡绿色 B=淡浅绿色 C=淡红色 D=淡紫色 E=淡黄色 F=亮白色

FileStorage类

filestorage类

time_t

数据类型,time_t的类型是8字节的有符号整数。
包含文件:<time.h>。在time.h头文件中,我们还可以看到一些函数,它们都是以time_t为参数类型或返回值类型的函数:

double difftime(time_t time1, time_t time0);
time_t mktime(struct tm * timeptr);
time_t time(time_t * timer);
char * asctime(const struct tm * timeptr);
char * ctime(const time_t *timer);

时间函数:将结构中的信息转换为真实世界的时间,以字符串的形式显示
#include <time.h>
char asctime(const struct tm timeptr);

直接把time_t类型的转换为我们常见的格式:

/* gettime2.c*/
#include <time.h>

int main()
{
    time_t timep;
   
    time(&timep); /*获取time_t类型当前时间*/   
    /*转换为常见的字符串:Fri Jan 11 17:04:08 2008*/
    printf("%s", ctime(&timep));
    return 0;
}

编译运行

$gcc -o gettime2 gettime2.c
$./gettime2
Sat Jan 12 01:25:29 2008

转载自:https://www.runoob.com/w3cnote/cpp-time_t.html

asctime

函数原型char* asctime (const struct tm * timeptr)。
把timeptr指向的tm结构体中储存的时间转换为字符串,返回的字符串格式为:Www Mmm dd hh:mm:ss yyyy。其中Www为星期;Mmm为月份;dd为日;hh为时;mm为分;ss为秒;yyyy为年份。

/* asctime example */
#include <stdio.h>      /* printf */
#include <time.h>       /* time_t, struct tm, time, localtime, asctime */
 
int main ()
{
    time_t rawtime;
    struct tm * timeinfo;
 
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    printf ( "The current date/time is: %s", asctime (timeinfo) );
 
    return 0;
}

编译结果

The current date/time is: Wed Feb 13 15:46:11 2013
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值