Image

Imageskreyola wrote in Imagecpp

Filestreams Behind a Dam

I have some old code from a year or two ago, and it worked fine then, but somewhere in the period between then and now, a lot of the stuff in it apparently became deprecated.
So, I'm trying to fix the code so it will compile, and I'm hitting a brick wall with it. No matter what I do, I can't get the compiler to recognize the file streams I'm trying to use.
Here's the code from one of the headers as it was originally:

#ifndef PARROT_H
#define PARROT_H

#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
#include "dora.h"
#include "dora_f.h"

void parrot(const char* flnm) {
ifstream polly(flnm, ios::binary | ios::in | ios::nocreate);
polly.seekg(0,ios::beg);
if (polly.bad() || !polly) {
cout << "File error encountered with \"" << flnm << "\". Please contact the system administrator!\n";
return;
}
char printthis;
polly.read(reinterpret_cast<char*>(&printthis),sizeof(char));
while (!polly.eof()) {
cout << printthis;
polly.read(reinterpret_cast<char*>(&printthis),sizeof(char));
}
polly.close();
}

#endif


Here's what I've done so far. I changed the included STL stuff from X.h to X. I changed the stdlib to cstdlib.
And I kept getting an error that 'ifstream' was not declared in this scope and that 'ios' has not been declared.
I did several searches online but haven't found anything that works. Based on suggestions found online, I've tried prepending ios:: on the ifstream, prepending fstream:: on the ifstream, #including the ios header, etc., but nothing works.
What do I need to do to make the filestreams work?
Also, I know ios::nocreate is no longer correct, according to what I've found online, but nobody has suggested a replacement for it so I don't create files that didn't exist when I try to open them for reading. What would be a good way to do this?