How to open a file using _TCHAR * as the file name? C / C ++

I have the following signature:

int _tmain(int argc, _TCHAR* argv[]) 

I would like to write the following:

 FILE *inputFilePtr; inputFilePtr = fopen(argv[2], "_r"); 

But there is a type mismatch. How am I supposed to do this? Should I use:

 inputFilePtr = _tfopen(argv[2], ??????); 

Thanks!

+4
source share
2 answers

Using:

 _tfopen(argv[2], TEXT("r")); 

Do not use:

 _tfopen(argv[2], L"r"); 

The second will give a compilation error if the UNICODE macro is not defined, that is, when the TCHAR is just char and not wchar_t .

+6
source

Use _tfopen(argv[2], TEXT("r"));

or _tfopen(argv[2], L"r"); if TCHAR is WCHAR.

0
source

Source: https://habr.com/ru/post/1344388/


All Articles