Line 42: it says "no matching function call to std::basic ifstream char..." and then in the next line it says "note: candidate is:. it works fine if I hardcode the file name into the program, but for some reason it wont let me let the user specify the name.
// lab 3: Madlibs game
// Written by:
// Date:
#include <iostream>
#include <cctype>
#include <string>
#include <fstream>
usingnamespace std;
int readFile(string ** story);
int main()
{
string * story;
int count = readFile(&story); // count is number of lines in the file
if (count == -1) // which is also the number of elements in the array
return 1;
/*play(story, count);
print(story, count);*/
return 0;
}
// readFile: read lines of the file into an array of C++ strings
// each line is a string element in the array
// input: address of the array
// return: -1 if file open fails
// number of lines in the file if file reading is successful
int readFile(string ** story)
{
ifstream inFile;
string filename;
string temp;
int count = 0;
cout << "Enter the name of the file." << endl;
cin >> filename;
inFile.open(filename);
if(inFile)
{
while (inFile >> temp)
{
inFile.ignore(80,'\n');
count++;
}
cout << count << endl;
inFile.close();
return count;
}
else
{
cout << "Error reading file." << endl;
return -1;
}
}
// print: print the story in the array
// input: address of array, number of elements
// return: nothing
// play: prompt the user with each keyword and replace the keyword with the user input
// user input must be a C string, and it can be multiple words
// user input is capitalized when stored in the string
// input: address of the array, number of elements
// return: nothing