문제

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