In this program I'm trying to read in a input file and outputting the contents onto the output file and console.
In the main, when I try to call the function openfile(), the compiler keeps saying "error: undefined reference to `openfile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_ifstream<char, std::char_traits<char> >&, std::basic_ofstream<char, std::char_traits<char> >&)'"
Help is much appreciated.
//read in file created by previous program
//display the contents onto screen
//allow user to enter data by rows and column
//editing can include deleting all content, change value of a particular cell or reload whole matrix with a range
//file will rewrite with modifications
if (argc !=6)
{
cout << "Enter filename:" << endl;
cin >> fileName;
}
else
{
fileName = argv[1]; //first argument is filename to be opened; argv [0] is file directory
}
}
void openfile(const string &fileName, ifstream &in_stream, ofstream &out_stream) //opens instream and outstream by file
{
in_stream.open(fileName.c_str());
in_stream.close();
if (in_stream.fail())
{
fflush(stdin); //clear file
string line;
cout << "File opening failed." << endl;
getline(cin, line);
cout << "That file already exists, do you want to (O)verwrite or (Q)uit?" << endl; //O keeps writing
if (toupper(line[0] != 'O'))
{
cout << "Program terminating" << endl;
exit(1);
}
}
out_stream.open(fileName.c_str());
}
void displayMatrix(ifstream &in_stream, ofstream& out_stream)
{
string matrixline;
while (!in_stream.eof()) //while not end of line
{
getline (in_stream, matrixline);
cout << matrixline << endl; //output to console
out_stream << matrixline << endl; //output to file