การเก็บข้อมูลกับTime stamp
การเก็บข้อมูลกับTime stamp
#include <ctime> ตัวอย่างที่6: เขียนข้อมูลและใส่เวลาที่เก็บข้อมูล
#include <iostream>
#include <fstream>
#include <ctime> // สำหรับอ่านค่าเวลา
using namespace std;
void file_create_ts(){ //ฟังก์ชั่นสร้างไฟล์
ofstream file;
file.open("datalogger_timestamp.txt");// สร้างไฟล์
time_t now = time(0); //สร้างตัวแปรที่เก็บค่าเวลาปัจจุบัน
for(int i=1;i<=5;i++){
file<<i<<" : "<<ctime(&now); //เขียนข้อมูลตัวเลข 1 ถึง 5 ทีละบรรทัด และต่อด้วยเวลา
}
file.close();
}
int main(){
file_create_ts();
return 0;
}
ตัวอย่างที่7: อ่านข้อมูลใส่ไฟล์โดยใช้ getline()

Last updated
Was this helpful?