我是C ++的初学者,我尝试编写一个程序,从我最喜欢的连续剧中随机生成一集,或绝对随机,但是当我调试它时,总会出现这个错误。
代码没问题,如果它不在Win32 Form应用程序中,它可以工作。
你能帮我吗?
我的列表项代码:
Void pro::Form1::keres(string sori) {
int k=0;
vector<string> a;
srand (time(NULL));
string desti = "d:\\Filmek\\Sorozatok\\" + sori + "\\*";
WIN32_FIND_DATA search_data;
int s;
memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
HANDLE handle = FindFirstFile(desti.c_str(), &search_data);
while(handle != INVALID_HANDLE_VALUE)
{
a.push_back(search_data.cFileName);
k++;
if(FindNextFile(handle, &search_data) == FALSE)
break;
}
s = rand() % (k-2);
cout<<a[s+2]<<endl;
desti = "d:\\Filmek\\Sorozatok\\" + sori + "\\" + a[s+2] + "\\*";
handle = FindFirstFile(desti.c_str(), &search_data);
k = 0;
while(handle != INVALID_HANDLE_VALUE)
{
a.push_back(search_data.cFileName);
k++;
if(FindNextFile(handle, &search_data) == FALSE)
break;
}
s = rand() % (k-2);
string run = "cd " + desti + " & start " + a[s+2];
system(run.c_str());
a.clear();
}
Void pro::Form1::kereses(string film) {
int q=0;
int w=0;
int e=0;
int a;
int s;
int d;
vector<string> y;
vector<string> x;
vector<string> v;
srand (time(NULL));
string desti = "d:\\Filmek\\" + film + "\\*";
WIN32_FIND_DATA search_data;
memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
HANDLE handle = FindFirstFile(desti.c_str(), &search_data);
while(handle != INVALID_HANDLE_VALUE)
{
y.push_back(search_data.cFileName);
q++;
if(FindNextFile(handle, &search_data) == FALSE)
break;
}
a = rand() % (q-2);
desti = "d:\\Filmek\\" + film +"\\" + y[a+2] + "\\*";
handle = FindFirstFile(desti.c_str(), &search_data);
y.clear();
q = 0;
while(handle != INVALID_HANDLE_VALUE)
{
x.push_back(search_data.cFileName);
w++;
if(FindNextFile(handle, &search_data) == FALSE)
break;
}
s = rand() % (w-2);
desti = "d:\\Filmek\\" + film +"\\" + y[a+2] + "\\" + x[s+2] + "\\*";
handle = FindFirstFile(desti.c_str(), &search_data);
x.clear();
w = 0;
while(handle != INVALID_HANDLE_VALUE)
{
v.push_back(search_data.cFileName);
e++;
if(FindNextFile(handle, &search_data) == FALSE)
break;
}
d = rand() % (e-2);
string run = "cd " + desti + " & start " + v[d+2];
system(run.c_str());
v.clear();
e=0;
}