no matching function error

this is the error on line 44 and 46 when I try to read the lines from the txt file:

no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::getline(char[30])'

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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;

/***********************
  structure definitions
************************/
struct Records
{
    char ID[8];       //id with 8 chars
    char name[30];    //full name (first and last) 30 chars
    char deptID[4];   //department id with 4 chars 
    char phoneNum[14];//phone number with 14 chars       
};
/****************prototypes*****************/
void getFile(Records label[], const int SIZE);
void output(Records label[], const int SIZE);
/******************mainline******************/
int main()
{
    const int SIZE = 26;  //26 records in the file
    Records label[SIZE];  //label is a Records structure
    
    getFile(label, SIZE); //call getFile
    output(label, SIZE);  //call output
    
    system("pause");
    return 0;
}


//function that opens and reads records into an array
void getFile(Records label[], const int SIZE)
{
    ifstream ifile("directory.txt"); //open the file
 
    if(ifile)
    {
        for(int i=0; i<SIZE && !ifile.eof(); i++)
        {
            ifile >> label[i].ID;
            ifile.getline(label[i].name);
            ifile >> label[i].deptID;
            ifile.getline(label[i].phoneNum);
        }
        ifile.close();
    }
    else
    {
        cout << "Could not open the input file\n";
        system("pause");
        exit(2);
    }       
}


//function that outputs the contents
void output(Records label[], const int SIZE)
{
    for(int i=0; i<SIZE; i+=2)
    {
        cout << "Employee ID: " << left << setw(22) << label[i].ID 
                                << left << setw(22) << label[i+1].ID <<endl;
        cout << "Employee name: "<<left << setw(28) << label[i].name 
                                << left << setw(28) << label[i+1].name << endl;
        cout << "Employee department: "<< left << setw(28) << label[i].deptID
                                << left << setw(28) << label[i+1].deptID <<endl; 
        cout << "Employee telephone: "<< left << setw(28) << label[i].phoneNum
                                << left << setw(28)<<label[i+1].phoneNum <<endl; 
    }         
}
The function std::ifstream::getline expects two arguments. The first you have provided correctly, but you also need a second integer parameter to specify the maximum number of characters to be read.

http://cplusplus.com/reference/iostream/istream/getline/
Topic archived. No new replies allowed.