I'm making a program with several functions:
int totalDays(ofstream &outputFile, int noEmployee)
{
string fileName = "employeeAbsences.txt";
outputFile.open(fileName);
However, I don't know how to call it:
int main()
{
int employeesNumber = employees();
string fileName = "employeeAbsences.txt";
employees();
totalDays(fileName, employeesNumber);
the fileName is underlined in the call saying it cannot be a string. What name am I supposed to call the first function with??
Let's declare (and define) the function correctly:
void totalDays(std::ofstream& outputFile,
int employee_quantity,
const std::string& filename)
{
outputFile.open(filename.c_str());
//...
}
Now to call it:
std::ofstream outputFile;
totalDays(outputFile, employeesNumber, fileName);
Your totalDays
function needs the output file (stream) to pass back to main
and it needs the name of file in order to open the file. So, you need to pass these items to your function.