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?

Recommended Answers

All 2 Replies

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

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().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.