I'm not quite certain how to tackle this. The following code is part of what I'm trying to compile. I've included the prototypes.h, the .cpp file for the error I'm receiving, and the main.cpp where the function is being used. The error I'm getting is:
undefined reference to `openfiles(int, char**, std::basic_ifstream<char, std::char_traits<char> >&, std::basic_ofstream<char, std::char_traits<char> >&)'
collect2: error: ld returned 1 exit status
I've never encountered the syntax in the prototype (ifstream &ifs, ofstream &ofs) before, so I'm not quite sure I wrote the parameters in the function right.
Any hints on how to resolve this? I feel I'm missing something basic.
NOTE: I have done searches on the subject, but I'm not sure I understand the answers I've read.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <ifstream>
#include <cstdlib>
using namespace std;
bool openfiles(int argc, char *argv[],ifstream &ifs in,ofstream &ofs out);
{
if (argc !>= 2)
{
cout << "Usage: " << argv[0] << " inputfile.\n";
exit(1);
}
//Check for a valid file.
in.open(argv[1]);
else if (in.fail())
{
cout << "Error opening file " << argv[1] << ". Doesn't exist?\n";
exit(1)
}
else if (argc != 3)
{
cout << "Output file not declared.\n";
exit(1);
}
else
out.open(argv[2]);
return true;
}
|
1 2 3 4 5 6 7 8 9 10
|
#include "arrayListType.h"
#include "Sentence.h"
#include <fstream>
#include <iostream>
#include <cstdlib>
//function prototypes
void read(ifstream&, arrayListType<Sentence>&);
void report(ofstream&,const arrayListType<Sentence>&);
bool openfiles(int argc,char *argv[],ifstream &ifs,ofstream &ofs);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "Sentence.h"
#include "arrayListType.h"
#include "prototypes.h"
using namespace std;
int main(int argc, char* argv[])
{
arrayListType<Sentence> sentences;
ifstream in;
ofstream out;
if (openfiles(argc,argv,in,out))
{
read(in,sentences);
report(out,sentences);
in.close();
out.close();
cout << "\ninput read from the file '" << argv[1] << "'\n";
cout << "output written to the file '" << argv[2] << "'\n";
}
return 0;
}
|