C + + File replication

Source: Internet
Author: User

1#include <iostream>2#include <fstream>3 4 voidCopyChar* SRC,Char*DST);5 intMain ()6 {7     using namespacestd;8     Charsrc[ -] ="E:/test/jdk-8u121-windows-x64.exe";9     Chardst[ -] ="E:\\test\\jdk-8u121-windows-x64_bak.exe";Ten copy (SRC, DST); One      A     return 0; - } -  the voidCopyChar* SRC,Char*DST) - { -     using namespacestd; -Ifstreaminch(src,ios::binary); +Ofstream out(dst,ios::binary); -     if(!inch. Is_open ()) { +cout <<"Error Open File"<< src <<Endl; A exit (exit_failure); at     } -     if(! out. Is_open ()) { -cout <<"Error Open File"<< DST <<Endl; - exit (exit_failure); -     } -     if(src = =DST) { incout <<"The src file can ' t be same with DST file"<<Endl; - exit (exit_failure); to     } +     Charbuf[2048]; -     Long LongTotalBytes =0; the      while(inch) *     { $         //read reads 2048 bytes from the in stream into the BUF array while the file pointer moves backwards by 2048 bytesPanax Notoginseng         //if less than 2048 bytes are encountered at the end of the file, the actual fetch bytes are read.  -         inch. Read (BUF,2048);  the         //Gcount () is used to extract the number of bytes read, and write writes the contents of the BUF to the out stream.  +          out. Write (BUF,inch. Gcount ());  ATotalBytes + =inch. Gcount (); the     } +     inch. Close (); -      out. Close (); $}

C + + File replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.