How do I fix this compiling error (probably dealing with an array).

Here is my code:
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
#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(getline(inFile,words))
    {
      index++;
    }
  inFile.close();
}


And here is the error that is showing up when I go to compile my program:

p1.cpp: In function `void populateArray(std::ifstream&, std::string*)':
p1.cpp:81: error: no matching function for call to `getline(std::basic_ifstream<char, std::char_traits<char> >&, std::string*&)'

Line 81 is while(getline(inFile,words))

I've never seen an error message like that before so I have absolutely no clue what I need to do to fix it.
getline accepts only 1 element (ie: 1 string)
line 81 is passing the whole array of strings into getline - which getline doesn't know what to do with...u want to pass in only 1 element of the 'word[]' array
try on line 81: while(getline(inFile,words[index]))

by contrast, line 25 is only passing 'word' ie: the whole array of strings because 'word' is a pointer to the first element of the array. there's no problem there because that's what the function prototype is expecting.
Last edited on
Topic archived. No new replies allowed.