Files , not compiling , any suggestions ?

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Record
{
string name;
int age;

};

string getFileName()
{
//makes a copy
string filename;
cout << "Enter Filename: ";
cin >> filename;
return filename;

}
void readFile(string filename, Record array[])
{
//open it
ifstream fin(filename.c_str());

//test it
if (fin.fail())
{

return -1;

}
//read it
int count = 0;
while(fin >> array[count].name)
{
fin >> array[count].age;
count++;
}
//close it
fin.close();

//return it
return count;
}



void display(Record array[], int size)
{
for (int i = 0; i < size; i++)
{
cout << i << ": " << array[i].name << ", " << array[i].age << endl;

}


}



int main()
{

//get the file from user
string filename = getFileName();

//read the file
Record array[500];
int count = readFile(filename, array);

//display it on the screen
display(array, count);

return 0;
}

Last edited on
Supposed to ask for a file and read it but its not compiling. Any help?
1
2
3
// Error! You can't return `count` from a function that returns nothing.
// void readFile(string filename, Record array[]) 
int readFile(string filename, Record array[])

Last edited on
Topic archived. No new replies allowed.