C ++ file copy application skills

Source: Internet
Author: User

In C ++ programming languages, file operations are a very important application technology. In this article, we will explain the application methods related to C ++ file copying in detail, so that we can get help in practical programming in the future.

Example of C ++ file copy code:

 
 
  1. # Include <iostream. h>
  2. # Include <afx. h>
  3. Void main ()
  4. {
  5. Char SourceName [81];
  6. Char DestinName [81];
  7. Cout <"\ n enter the source file name :";
  8. Cin> SourceName;
  9. Cout <"\ n enter the target file name :";
  10. Cin> DestinName;
  11. Try
  12. {
  13. CFile fileSource (SourceName, CFile: modeRead );
  14. CFile fileDestin (DestinName, CFile: modeCreate | CFile: modeWrite );
  15. Char c;
  16. While (fileSource. Read (& c, 1 ))
  17. FileDestin. Write (& c, 1 );
  18. }
  19. Catch (CFileException * e)
  20. {
  21. Switch (e-> m_cause)
  22. {
  23. Case CFileException: fileNotFound:
  24. Cout <"file not found! "<Endl;
  25. Break;
  26. Case CFileException: badPath:
  27. Cout <"path input error! "<Endl;
  28. Break;
  29. Case CFileException: accessDenied:
  30. Cout <"no access permission! "<Endl;
  31. Break;
  32. Case CFileException: diskFull:
  33. Cout <"Disk Full! "<Endl;
  34. Break;
  35. Default:
  36. Cout <"an unknown error occurred during file copy! "<Endl;
  37. Break;
  38. }
  39. }
  40. }

The preceding section describes how to copy C ++ files.

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.