文件拷贝小程序_0000_build200322

要求:

将某文件拷贝到另一个地址,并用sleep()函数控制进度。

#include<iostream>
#include<fstream>
#include<string>
#include<Windows.h>
using namespace std;

int main()
{
	//  打开源文件fpO.txt和目标文件fpT.txt
        //  注意源文件要和main.cpp在同一级哦
	ifstream fin("fpO.txt");
	ofstream fout("D:\\fpT.txt");


	//  如果打开文件失败报告错误
	if (!fin.is_open() || !fout.is_open())
	{
		cout << "Failed to open file!" << endl;
		return -1;
	}
	cout << "Open file successfully!" << endl;


	//  buf取字符串
	string buf;
	
	//  设置两个计数器
	int i = 0, j = 0;


	//  循环读取、写入
	while (!fin.eof())
	{
		fin >> buf;

		fout << buf << " ";
		
		i++;  /* 记录读取次数  */

		if (i%30==0)  /*每取30个字符串休眠1秒*/
		{
			j++;  /*记录休眠次数*/

			Sleep(1000);

		}
	
		//清空字符
		buf.clear();
	}


	cout << "fpO.txt has " << i << " strings." << endl;

	cout << "Sleep for " << j << " seconds in total." << endl;

	cout << "\nExecution completed, Please check fpT.txt!" << endl;

	//关闭文件
	fin.close();
	fout.close();

	system("pause");
	return 0;
}

可能是程序太小了,sleep()函数看不出什么效果。

 

每天都要进步一点点哦~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值