I am using Visual Studio 2013
So, I need to open the .ppm image file and work on it a bit, but ifstream, which I am trying to use to read data, cannot open the image file. I am sure that the image file is in the working directory (I created and read some simple .txt files to make sure). And even after extensive research, I cannot understand what is happening.
Here is the corresponding code
EDIT: I added some more code to understand what I'm trying to do
Image * PPMImageReader::read(std::string filename){
std::string line;
int width, height, max_val;
std::ifstream src(filename, std::ios_base::binary);
if (src.fail()) {
perror("Logical error on i/o operation. failbit was set\n");
if (src.bad())
perror("Read/writing error on i/o operation. badbit was set");
}
if (!src.is_open()) {
printf("File was not opened\n");
exit(1);
}
getline(src, line, '\n');
if (line.empty())
getline(src, line);
if (line.find("P6") == std::string::npos) {
printf("wrong format\n");
exit(1);
}
Velix source
share