Is this the proper way to open a file for input?
void BinaryTree::read(char * path, int line_number)
{
ifstream * file(path); //error: cannot convert ‘char*’ to ‘std::ifstream*’ in initialization
file->seekg(0, std::ios::beg);
int length = file.tellg();
char * buffer = new char[length];
file->getline(buffer, line_number);
printf("%d", length);
file->close();
}
I’m guessing not, because the compiler won’t accept a char array, or a std::string for the ifstream constructor, yet when I read documentation, I see strings and/or char arrays being passed to ifstream constructors.
Is something wrong with my compiler or am I just using the wrong type in my parameter?
Dont use pointer. It is not needed here.
Try this:
and then use it as: