这个东西其实早就弄出来了,只不过手贱给删了。
生成代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <cstdio> #include <cstdlib> #include <ctime> int main(int argc,char**argv) { if(argc<=2) { printf("Usage: test.exe [file_name] [file_size(MB)]\n"); return 0; } long size=atoi(argv[2]); if(size<=0 || size>1024) { printf("Invalid size !\n"); return 0; } FILE*fp=fopen(argv[1],"wb"); if(fp==NULL) { printf("Couldn't open \"%s\"!\n",argv[1]); return 0; } printf("Open successfully!\n"); size*=1024*1024; long nW=0;unsigned char c[1]={0}; srand(time(NULL)); while(nW<size) { c[0]=rand()%256; fwrite(&c,1,1,fp); nW++; if(nW%(5*1024*1024)==0) printf("Progress: %.2lf/%.2lf %.0lf%\n",nW/1024.0/1024.0,size/1024.0/1024.0,(double)nW/(double)size*100.0); } fclose(fp); printf("Write successfully!\n"); return 0; } |
测试链接: 5MB 10MB 20MB 50MB 100MB 200MB 500MB
(我也不知道为什么要弄这么多个