zoukankan      html  css  js  c++  java
  • c++获取系统当前时间写入txt文件

    头文件:iomanip
    代码实践:

    #include <iomanip>      //获取系统当前时间头文件
    using namespace std;
    //存入每次检测到的目标数据txt文件追加模式
    int main(){
    	ofstream outfile;
    	SYSTEMTIME sys;       // 定义一个 SYSTEMTIME 结构体 sys
    	outfile.open("footlog.txt", ios::in || ios::trunc);
    	if (!outfile) cout << "footlong.txt error " << endl; //文件打开错误
    while(1){
    if (irbuff[0]){
    			
    GetLocalTime(&sys);   // GetLocalTime是一个Windows API 函数,用来获取当地的当前系统日期和时间。
    outfile << std::setfill('0') << std::setw(2) << sys.wHour
    				<< ":" << std::setfill('0') << std::setw(2) << sys.wMinute << ":" << std::setfill('0') << std::setw(2) << sys.wSecond;
    outfile << "1:" << irbuff[0] << "," << irbuff[1] << " " << endl;
    		}
    }
    outfile.close();         //关闭文件
    return 0;
    }
    
    

    运行结果:

    前面是小时:分:秒,后面是我自己测的的数据。
    至于if语句内容,自己根据需求修改。

    一键三连呀!
  • 相关阅读:
    雷林鹏分享:CSS 链接
    雷林鹏分享:CSS 字体
    雷林鹏分享:CSS 文本格式
    转载:64,32位编程问题
    NSTimer 线程操作
    安装推送
    短信在没有网络情况下崩溃
    使用Html来避免写复杂的app代码,跨平台
    ios推送
    APN 推送
  • 原文地址:https://www.cnblogs.com/jee-cai/p/14095311.html
Copyright © 2011-2022 走看看