Pregunta

I write

FILE * new_file = fopen("Penguins.jpg","rb");

I fully confident that file exist and it is in right directory. I also tried a lot of various modes like "rb+" "r". I also chanded path like fopen("C:\Penguins.jpg","rb"); Compilator always says :

enter image description here

Besides, openCV open the file. But i need in FILE*. What wrong?

¿Fue útil?

Solución 2

According to the documentation of fopen from http://www.cplusplus.com/reference/cstdio/fopen/

The file opens successfully is the function returns a non-null pointer:

If the file is successfully opened, the function returns a pointer to a FILE object that can be used to identify the stream on future operations. Otherwise, a null pointer is returned.

So because your variable new_file (not new_file->_ptr) is valid, the file should be opened.

Otros consejos

In order to denote a special character within a string, it must be preceded with a backslash.

Since the backslash itself is also a special character, it must be preceded with yet another backslash.

So change this:

fopen("C:\Penguins.jpg","rb");

To this:

fopen("C:\\Penguins.jpg","rb");

Please note that you need to apply this only for strings that are part of the code, i.e., strings that are "treated" by the compiler, not by the preprocessor (such as names of included header files, for example).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top