error: no matching function for call to `getline(char[51], std::string&)'

I'm working on an assignment for my computer science class. I was able to use an input file to store data into three separate arrays, and then I realized when I reread the assignment that I need to have the program ask the user what input file to use. I changed my code to reflect that and got this far and can not get past this error: line 23:
no matching function for call to `getline(char[51], std::string&)'


This syntax worked when I specified the input file as "inputFile.txt" but now that I have changed it to a variable, i get an error using this syntax. I'm a little lost and cant seem to find out how to do this in my book, or help on the error message online, so I'm posting here. Any ideas? Thanks!

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
const int AR_SIZE = 10;
    string namesAR[AR_SIZE];
    int idsAR[AR_SIZE];
    float balance[AR_SIZE];
    int indexCount;
    int count;
    char inputFile[51];
    string outputFile;
    ifstream inFile;
    ofstream outFile;
    
    cout << "What input file should I use?";
    cin >> inputFile;
    
    // opens the file named InputFile.txt as an input file
    inFile.open(inputFile);
    
    cout << "What output file should I use?";
    cin >> outputFile;

    for(indexCount = 0; indexCount < 11; indexCount++)
    {
    getline(inputFile, namesAR[indexCount]);
    inFile >> idsAR[indexCount] >> balance[indexCount];
    inFile.ignore();
    }
Last edited on
inputFile is a char array: char inputFile[51];

inFile is your ifstream: ifstream inFile;

You got these two mixed up. You probably meant to do this: getline(inFile, namesAR[indexCount]);


The lesson here is to make less confusing names. 'inputFile' doesn't represent a file, it reprents the name of a file, so a better name would be 'inFileName' or the like.

You might also run into confusion with other similar names, such as 'count' and 'indexCount'
Topic archived. No new replies allowed.