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?

有帮助吗?

解决方案 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.

其他提示

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top