用C++输出.dat数据文件里的内容

本文展示了如何使用C++编程从.cet4_word.dat文件中读取单词,并设定间隔时间动态显示。程序包含文件操作、时间延迟功能,适于学习C++文件I/O和控制流程。
摘要由CSDN通过智能技术生成

       近日,下了<三心二意背单词>,发现这个软件超级简单,尝试着用C++把它的单词数据调出来,还设置了单词输出的间隔时间!

#include<iostream>
#include<stdio.h>
#include<process.h>
#include<string>
using namespace std;

void Dtime(int dt) {
    time_t current_time;
    time_t start_time;
    // 得到开始时间
    time(&start_time);
    do
    {
      time(&current_time);
    }
    while ((current_time - start_time) < dt);
}

main(){
   FILE *fp;
   char p[100];
   int t;
  
   cout<<"输入单词显示间隔时间(seconds):";
   cin>>t;
   if ((fp=fopen("cet4_word.dat","r"))==NULL)
   {
        cout<<"/nCould not open the file."<<endl;
        cout<<"Exiting program."<<endl;
        exit(1);
       }
   while (fgets(p,100,fp)!=NULL)
   {
         cout<<p;
         Dtime(t);
        } 
      
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值