Hello
I am reading a text file & I want to make a for loop, loop repeatedly until the end of the file.
Is my code below correct, in terms of syntax? Is this possible to do.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// function prototypes
void printMenu();
int main()
{
const int MAX = 250000;
string words[max];
int nWord;
ifstream dict;
dict.open("dict.txt");
if (dict.fail())
{
cout << "No dictionary file" << endl;
system("pause");
return 0;
}
// read dictionary into array to make multiple searches faster
while (dict) {
for (int i=0; i<dict.eof; i++) { // This is the loop I am referring to :)
getline(dict,words[i],'\n');
nWord = i;
}
}
cout << nWord << endl << endl;
if (nWord > MAX) {
cout << "Error - Dictionary size of out of bounds";
system("pause");
return 0;
}