c积累

1.调用系统
int main(){
system("rm /home/book/fujinbing");
}
2.得到当前绝对路径,string 赋值,sting数组显示
#include <string>
#include <iostream>
using namespace std;

int main(){
char buf[1024];
getcwd(buf,1024);
printf("%s\n",buf);
string tmppath;
tmppath=buf;
cout<<buf<<endl;
cout<<buf[0]<<endl;
return 1;
}
3.去掉一行 的 0x0d回车 0x0a 换行键 0x09 水平置标符 0x20 空格 ,erase 删除
while ( ( tmpsflen > 0 ) && ( ( filepath[ tmpsflen - 1 ] == (char)0x0d )|| ( filepath[ tmpsflen - 1 ] == (char)0x0a )|| ( filepath[ tmpsflen - 1 ] == (char)0x20 )|| ( filepath[ tmpsflen - 1 ] == (char)0x09 ) ) )
{
filepath.erase( tmpsflen - 1 , 1 ) ;
tmpsflen -- ;
}

4.c++方式 得到文件流 读取1行数据
fstream tmpfp ("Config.dat",ios base :: in);
构造 tmpfp实例
string tmpstr ;
getline( tmpfp , tmpstr )

5.时间,时间格式
#include <time.h>
#include <stdio.h>
int main(){
time_t lt;
printf("%ld\n",lt); //
lt=time(NULL);
printf("%ld\n",lt); //据1900的时间戳
struct tm *st;
st=localtime(&lt);
printf("%d\n",st->tm_sec);
printf("%d\n",st->tm_min);
printf("%d\n",st->tm_hour);
printf("%d\n",st->tm_mday);
printf("%d\n",st->tm_mon);
printf("%d\n",st->tm_year);
printf("%d\n",st->tm_wday);
printf("%d\n",st->tm_yday);
printf("%d\n",st->tm_isdst);
return 1;
}

struct tm
{
int tm_sec; /* Seconds. [0-60] (1 leap second) */
int tm_min; /* Minutes. [0-59] */
int tm_hour; /* Hours. [0-23] */
int tm_mday; /* Day. [1-31] */
int tm_mon; /* Month. [0-11] */
int tm_year; /* Year - 1900. */
int tm_wday; /* Day of week. [0-6] */
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/

#ifdef __USE_BSD
long int tm_gmtoff; /* Seconds east of UTC. */
__const char *tm_zone; /* Timezone abbreviation. */
#else
long int __tm_gmtoff; /* Seconds east of UTC. */
__const char *__tm_zone; /* Timezone abbreviation. */
#endif
};

6.文件属性
1 函数都是获取文件(普通文件,目录,管道,socket,字符,块)的属性。
函数原型
#include <sys/stat.h>
int stat(const char *restrict pathname, struct stat *restrict buf); 提供文件名字,获取文件对应属性。
int fstat(int filedes, struct stat *buf); 通过文件描述符获取文件对应的属性。
int lstat(const char *restrict pathname, struct stat *restrict buf); 连接文件描述符,获取文件属性。

2 文件对应的属性
#include <stdio.h>
#include <string>
#include <sys/stat.h>
using namespace std;
int main(){
struct stat at;
string filename ="./aa";

stat(filename.c_str(),&at);

printf("%d\n",at.st_ctime);
return 1;
}
struct stat {
mode_t st_mode; //文件对应的模式,文件,目录等
ino_t st_ino; //inode节点号
dev_t st_dev; //设备号码
dev_t st_rdev; //特殊设备号码
nlink_t st_nlink; //文件的连接数
uid_t st_uid; //文件所有者
gid_t st_gid; //文件所有者对应的组
off_t st_size; //普通文件,对应的文件字节数
time_t st_atime; //文件最后被访问的时间
time_t st_mtime; //文件内容最后被修改的时间
time_t st_ctime; //文件状态改变时间
blksize_t st_blksize; //文件内容对应的块大小
blkcnt_t st_blocks; //伟建内容对应的块数量
};


7.编译时链接库 -lpthread链接pthread库。-ltr链接clock_gettime函数相关库 -lssl 链接 md5相关
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值