I have a couple errors that I don't understand and am not even sure how to go about searching this on the internet. I've tried "Opening files in C++ function," as well as the exact error, 0 but didn't get much help in the first few pages. This has been giving me a headache for a while now, and not even my instructor could help a whole lot. Though this IS the way he wanted it done, somehow. And yes, this is for a homework assignment.
The errors:
\driver.cpp: In function
void openFile(std::ifstream&, std::ofstream&)': \driver.cpp:63: error: no matching function for call tostd::basic_ifstream >::open(std::string&)' ../include/c++/3.4.2/fstream:570: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits] J:\Class_Files_2013_Fall\Advanced C++\Week1\Lab_2(Letter_Counter)\driver.cpp:68: error: no matching function for call to `std::basic_ofstream >::open(std::string&)' ../include/c++/3.4.2/fstream:695: note: candidates are: void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits]
So in main, I have:
ifstream inFile;
//defines the file pointer for the text document
ofstream outFile;
//the file pointer for the output file
openFile(inFile, outFile);
//allow the user to specify a file for reading and outputting the stats
And then the function:
void openFile(ifstream& inF, ofstream& outF){
// Ask the user what file to READ from
string readFile, writeFile;
cout << "Enter the name of the file you want to READ from: ";
cin >> readFile;
cout << endl;
// Open the File
inF.open(readFile);
// Ask the user what file to WRITE to
cout << "Enter the name of the file you want to WRITE to: ";
cin >> writeFile;
cout << endl;
outF.open(writeFile);
}
I have also implemented the:
#include <fstream>
And:
using namespace std;
The things that were in the main were put there by the instructor, so I can't change those. In other words, I HAVE to pass the file pointers into the openFile function and ask the user for the names of the files. However, I was never taught how to do this. A basic answer would be appreciated, going off what I've already been doing.