我想运行这个,但该文件不断加载失败。我想要做的是将一个字典加载到一个数组的每个级别占一个字的数组。试图打开文件使用fstream,但它不工作
#include <iostream>
#include <string>
#include <fstream>>
#include <time.h>
#include <stdlib.h>
using namespace std;
int Rand;
void SetDictionary(){
srand(time(NULL));
Rand = rand() % 235674;
fstream file("Hangman.txt");
if(file.is_open()){
string Array[235675];
for(int X = 0; X < 235673; X++){
file >> Array[X];
}
cout << Array[Rand];
}else{
cout << "Unable To Open File\n";
}
}
int main(){
SetDictionary();
}
如果文件不完全具有235675个字,会发生什么情况? –
我很确定这是一些环境问题;设置正确的路径并从相对于它的正确目录运行。 – legends2k
正如你可能会告诉我,我是一个初学者在C + +和文件实际上有235674字(我解决了这个问题,我认为)。谢谢。 – user3487267