Trying to read words from a file into an array but still getting compiling errors.

I am still getting compiling errors. What I am trying to do is take a word 1 by 1 & put them into an array which in this case is labeled as "words". I contacted my instructor on this code & he told me that I am not supposed to use any form of "getline" within the "populateArray" function located at the bottom. So I switched up the populateArray function since he said I need a "inFine >> ______" somewhere. I'm not sure what I am supposed to put in the blank so I put in the only thing that made sense to me which was "words[]", but now I am still getting a compiling & I cannot figure out for the life of me what I am doing wrong. At the very bottom after the code, I've listed the compiling error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
#include<fstream>
using namespace std;

// Function Prototypes
void readFilename(ifstream&, string&);
void countNumberLines(ifstream&, int&);
void countNumberChars(ifstream&, int&);
void populateArray(ifstream&, string[]);

int main()
{
  // Variables
  ifstream inFile;
  string filename;
  int countLines;
  int countChars;
  char ch;
  string words[1000];

  // Function Calls
  readFilename(inFile, filename);
  countNumberLines(inFile, countLines);
  countNumberChars(inFile, countChars);
  populateArray(inFile, words);

  return 0;
}

// Function: readFilename
void readFilename(ifstream &inFile, string &filename)
{
  // Reads in file name.
  cout << "Please enter the file name you wish to open." << endl;
  getline(cin, filename);
  inFile.open(filename.c_str());

  // Displays error message if file is not found.
  if (!inFile)
    {
      cout << "This file did not open properly and the program will now terminate.\nPlease make sure the spelling of the file is\
 correct." << endl;
    }
}

// Function: countCharsLines
void countCharsLines(ifstream &inFile, int &countLines, int &countChars, char &ch)
{
  string line;
  countLines = 0;
  countChars = 0;

  while(!inFile.eof())
    {
      getline(inFile,line);
      countLines++;
    }

  inFile.clear();
  inFile.seekg(0, ios::beg);

while(!inFile.eof())
    {
      ch = inFile.get();
      countChars++;
    }

  inFile.close();
}

// Function: populateArray
void populateArray(ifstream &inFile, string words[])
{
  int index = 0;

  while(!inFile.eof())
    {
      inFile >> words[];
      index++;
    }
  inFile.close();
}

The compiling error is:
p1.cpp: In function `void populateArray(std::ifstream&, std::string*)':
p1.cpp:83: error: expected primary-expression before ']' token

I have no clue what the means & line 83, which it states the problem is occurring is this line of code in the "populateArray" function:
inFile >> words[];
You want to change inFile >> words[]; to inFile >> words[index];. Simple mistake, you probably just needed another pair of eyes. This is assuming the rest of the code is correct.
Topic archived. No new replies allowed.