Hi,
Most examples for using ifstream don't use ifstream pointers. I thought this would not be a problem but I cannot seem to get my code working. The below gives me the error, "read has not been declared", but fstream is included. I supposed I needed to dereference fp but that changes nothing. Then I thought that the dereferencing might have lower precedence then the dot, so I also tried (*fp).read... which compiles fine but crashes at runtime.
#include <fstream>
#include <string>
#include <iostream>
usingnamespace std;
void read_data() {
ifstream f;
f.open("afile.txt");
ifstream* fp = &f;
// actually I have f opened elsewhere in the program and this function
// uses a pointer to it but I've included all the relevant code here
// for completeness.
char* c;
int len = 5;
c = newchar[50];
fp.read(c,len);
cout << c << "\n";
delete[] c;
}