将mcl中与系统相关的函数用c++标准库替代
来源:互联网 发布:名媛风的淑女打扮知乎 编辑:程序博客网 时间:2024/06/05 15:45
1、判断文件是否存在,存在则删除
#include<stdio.h>#include<iostream>int main(void){ char *filename = "who.txt"; FILE * f; f = fopen(filename,"r"); if (f == 0) printf("file not exist"); else { remove(filename); printf("file exist"); } system("pause"); return 0;}
2、gettimeofday
#include<chrono>#include<iostream>int main(){ std::chrono::high_resolution_clock::time_point tm_now = std::chrono::high_resolution_clock::now(); std::chrono::steady_clock::duration tm_s =tm_now.time_since_epoch(); std::cout << tm_s.count() << std::endl; time_t t_sec = (tm_s.count() / 1000000000); int t_msec = (tm_s.count() - tm_s.count() / 1000000000 * 1000000000) / 1000000; std::cout << t_sec << std::endl; std::cout << t_msec << std::endl; system("pause"); return 0;}
阅读全文