class ifstream variable not recognised from header file

I am attempting to write a script to extract a table of information from a PDF file, that is in a standard format.

I have started to write a class definition for the extraction, but I am struggling to move the definitions from the .cpp file to the header file.

In particular, the code:
getline(fsPDF,version);
reports:
Error: no instance of overloaded function "getline" matches the argument list

The code works if the class definition is in the PDF.cpp file, but not once it has been moved to the header file.

The compiler does not seem to recognise the ifstream fsPDF as an ifstream variable. Could someone please advise what code changes I need to make?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// PDF.h
#include<string>
#include<iostream>
#include<fstream>

#ifndef PDF_h
#define PDF_h

namespace document {
	class PDF {
		public:
			PDF(std::string Filename);
		private:
			ifstream fsPDF;
			string version;
			void ExtractVersion();
	};
};
#endif // PDF_h 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// PDF.cpp
#include "PDF.h"

namespace document {
	using namespace std;

	PDF::PDF(std::string Filename) {
		try {
			fsPDF.open(Filename, ios::in | ios::binary);
			ExtractVersion();
		}
		catch (exception& e) {
			cerr << e.what() << endl;
		}
	};

	void PDF::ExtractVersion() {
		// Read the first line of the document
		fsPDF.seekg(0, ios::beg);
		getline(fsPDF,version);
	};
};
std::ifstream, std::string, std::getline, etc.
Topic archived. No new replies allowed.