I'm a student and I'm trying to make a hangman program. I'm given a file called words.dat that I'm supposed to use for my hangman program, but I don't know how to store the data and put it into a string array. I'm trying to create a function dedicated to importing the file. I don't know how may words will be in the dat file but my teacher said there would be 100 at most. This was my rough guess on how to do it, but I only get a lot of errors trying to compile it. How do I get the words from the dat file into the string array?
words.dat
COW
SCHOOL
KEY
COMPUTER
my function so far
#include <string>
#include <fsteam>
using namespace std;
bool initializeFile(string filename){
int importWord = 0;
string words[100];
ifstream input;
input.open(filename, 'r');
if(input.fails){
return false;
}
/*
Tring to make for loop that runs through
all the characters in input(dat file) and
store them into the words array. if the character isn't a letter it
skips it and continues to the next row
*/
for(int i=0;i< input.length();i++){
if(input[i] =="\n"){
importWord++;
}
if(input[i] != "\n"){
words[importWord]=input[i];
}
}
return true;
}