For CopyFile function, refer to: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363851 (v=vs.85). aspx
Ide:code::blocks 16.01
Operating system: Windows 7 x64
1#include <windows.h>2#include <stdio.h>3 4 intMain ()5 {6 DWORD dwerror;7 8 if(CopyFile ("H:\\c++\\newdirectory\\file.txt","H:\\c++\\newdirectory\\del.bat", FALSE)) {9printf"Copy file succeeds. \ n");Ten } One Else { ADwerror =GetLastError (); - Switch(dwerror) { - CaseError_file_not_found: theprintf"The source file does not exist. \ n"); -printf"Error:%ld \ n", dwerror); - Break; - default: +printf"The new file already exists. \ n"); -printf"Error:%ld \ n", dwerror); + Break; A } at } - - return 0; -}
Ide:microsoft Visual Studio Community 2017 15.5.2
Operating system: Windows 7 x64
1#include"stdafx.h" /*created by the IDE itself*/2 3#include <windows.h>4 5 intMainintargcChar**argv)6 {7 DWORD dwerror;8 9 if(CopyFile (L"H:\\c++\\newdirectory\\file.txt", L"H:\\c++\\newdirectory\\del.bat", FALSE)) {Tenprintf"Copy file succeeds. \ n"); One } A Else { -Dwerror =GetLastError (); - Switch(dwerror) { the CaseError_file_not_found: -printf"The source file does not exist. \ n"); -printf"Error:%ld \ n", dwerror); - Break; + default: -printf"The new file already exists. \ n"); +printf"Error:%ld \ n", dwerror); A Break; at } - } - - GetChar (); - - return 0; in}
C + + CopyFile ()