寫程序: 每個2秒寫入文本一個數字;
讀程序: 每個5秒讀入文本最後一個數字;
寫程序代碼:
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main (void) {
ofstream ofs("D:/w.txt");
int num = 0;
while (1) {
ofs << ++num << std::endl;
std::cout << num << std::endl;
Sleep(2000);
}
ofs.close();
return 0;
}
輸出:
