- /*
- * File: readuntil.cpp
- * Author:yy
- *
- * Created on 2013年8月30日, 上午10:44
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <unistd.h>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main(int argc, char* argv[]) {
- if (argc != 3){
- cout<<argv[0]<<" [in_file] [max_time]"<<endl;
- return 1;
- }
- time_t max_time = atol(argv[2]);
- ifstream ifs;
- ifs.open(argv[1], ios::in);
- if (!ifs) {
- cout<<"open erro"<<endl;
- return 1;
- }
- string row;
- size_t seek;
- time_t t;
- do{
- if (ifs.peek() == EOF) {
- time(&t);
- if (t>max_time){
- break;
- }
- ifs.clear();
- ifs.seekg(seek, ios::beg);
- sleep(3);
- continue;
- }
- getline(ifs, row);
- cout<<row<<endl;
- seek = ifs.tellg();
- }while(1);
- ifs.close();
- return 0;
- }
C++时时读取txt文件
最新推荐文章于 2023-01-06 17:30:34 发布