Help: "Undefined reference to" error

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.

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

using namespace std;

//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

void parseCommandLine (int argc, char *argv[], string &fileName); //input by cin or arguments
void openfile (const string fileName, ifstream& in_stream, ofstream& out_stream); //open instream and outstream
void displayMatrix (ifstream &in_stream, ofstream& out_stream);


int main(int argc, char *argv[])

{
string fileName;

ifstream in_stream;
ofstream out_stream;
parseCommandLine(argc, argv, fileName);
openfile(fileName, in_stream, out_stream); //<-----
displayMatrix(in_stream, out_stream);

return 0;
}

void parseCommandLine(int argc, char *argv[], string &fileName)
{

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

}
}
Last edited on
Juxtapose the definition and declaration's signatures:
1
2
void openfile(const string  fileName, ifstream& in_stream, ofstream& out_stream)
void openfile(const string &fileName, ifstream &in_stream, ofstream &out_stream)

They don't match.
Last edited on
I see. Thanks for the help!
Topic archived. No new replies allowed.