0

Hello im new to daniweb and c++ and am getting a overloaded function error on my readFile function, specifically the string data type. I cant seem to pinpoint whats causing the error. Im supposed to use the function to read data from a text file in this format:

Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800

Here is my code:

#include <iostream> 
#include <string>
#include <fstream>
#include <iomanip>


void readFile(string listA[], int listB[]);


using namespace std;

int main()
{
   int votes[5];
   string politicians[5];

   ifstream inFile;

   readFile(politicians, votes);



   return 0;
}

void readFile(string listA[], int listB[])
 {
   ifstream inFile;
   inFile.open("politicians.txt");
   int noOfPoliticians = 0;

   inFile >> listA[noOfPoliticians] >> listB[noOfPoliticians];
   cout << listA[noOfPoliticians] << listB[noOfPoliticians] << endl;

 while (inFile && noOfPoliticians < 5)
 {
    noOfPoliticians++;
    inFile >> listA[noOfPoliticians] >> listB[noOfPoliticians];

    cout << listA[noOfPoliticians] << listB[noOfPoliticians] << endl;
 }

}

the compiler doesnt find any errors if i change the string data type to char but that wont give me all the data. What am i missing?

Edited by slaythezeppelin: append to article

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by rubberman
0

Move line 10 - using namespace std;
before the reafFile(.....) function declaration in line 5.
and all should complie ok.

0

Try a different name, such as myReadFile() instead, as this may be conflicting with some other function of the same name. Alternatively, you might try placing the using namespace std; directive before the declaration of readFile().

Edited by pritaeas: Replaced bbcode.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.