我开始在垃圾文件生成器上进行开发,但是由于某种原因,如果我使用大量文件,它将无限发出哔哔声,直到文件完成,我认为 ascii 表中的某处有一个 \a 字符,或者它正在溢出并导致错误提示音。有人想解释为什么这东西对我尖叫吗?
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <time.h>
#include <windows.h>
#define print cout<<
using namespace std;
int numberof,i;
char charvalue;
string charlist,filename;
int main()
{
srand (time(NULL));
print "What do you want the name of your file to be?(with a .txt extension)\n";
getline(cin,filename);
print "\nHow many characters do you want?\n";
cin>>numberof;
for(numberof>0;numberof!=0;numberof--)
{
i = rand() % 255 + 32;
charvalue=i;
charlist=charlist+charvalue;
print charlist;
}
ofstream writefile(filename.c_str());
writefile<<charlist;
writefile.close();
ShellExecute(NULL, "open", filename.c_str(), NULL, NULL, SW_SHOWNORMAL);
return 0;
}
似乎在这一点上,这些字符最终会出现,但它只将其中的 1/4 写入文本文件。有谁知道为什么?