fork download
  1. #include <windows.h>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. const char * src_file = "QFN64 230551-CU-A";
  8. const char * dst_file = "Test";
  9.  
  10. int main()
  11. {
  12. int file_size = 0;
  13. string m_Path = src_file;
  14.  
  15. WIN32_FIND_DATAA file_data;//取得File檔案資訊
  16. HANDLE handle;
  17. handle = ::FindFirstFileA(m_Path.c_str(), &file_data);
  18. if( handle != INVALID_HANDLE_VALUE )
  19. {
  20. ::FindClose(handle);
  21. if ( !(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
  22. {
  23. file_size = file_data.nFileSizeLow;////取得File檔案大小
  24. }
  25. puts("Success!!");
  26. } else {
  27. puts("Error!!");
  28. }
  29.  
  30. FILE *fp = fopen(src_file, "rb");
  31. char *buf = (char*)malloc(file_size+10);
  32.  
  33. if(buf==NULL){
  34. puts("allocate fail.");
  35. getchar();
  36. return 1;
  37. }
  38.  
  39. size_t ret = fread(buf, 1, file_size, fp);
  40. printf("file_size = %u, ret = %u\n", file_size, ret);
  41. buf[file_size] = 0;
  42.  
  43. FILE *fw = fopen(dst_file, "wb");
  44. fwrite(buf, sizeof(buf[0]), file_size, fw);
  45. fclose(fw);
  46.  
  47. free(buf);
  48. getchar();
  49. return 0;
  50. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:21: error: windows.h: No such file or directory
prog.cpp: In function ‘int main()’:
prog.cpp:15: error: ‘WIN32_FIND_DATAA’ was not declared in this scope
prog.cpp:15: error: expected `;' before ‘file_data’
prog.cpp:16: error: ‘HANDLE’ was not declared in this scope
prog.cpp:16: error: expected `;' before ‘handle’
prog.cpp:17: error: ‘handle’ was not declared in this scope
prog.cpp:17: error: ‘::FindFirstFileA’ has not been declared
prog.cpp:17: error: ‘file_data’ was not declared in this scope
prog.cpp:18: error: ‘INVALID_HANDLE_VALUE’ was not declared in this scope
prog.cpp:20: error: ‘::FindClose’ has not been declared
prog.cpp:21: error: ‘FILE_ATTRIBUTE_DIRECTORY’ was not declared in this scope
prog.cpp:44: warning: ignoring return value of ‘size_t fwrite(const void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
stdout
Standard output is empty