4

My main has the following signature:

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

I would like to preform the following:

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

But there is a type mismatch. How should I do it? Should I use:

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

Thanks!

Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111
M.N
  • 333
  • 3
  • 9

2 Answers2

7

Use:

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

Do not use:

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

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

Nawaz
  • 353,942
  • 115
  • 666
  • 851
0

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

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

Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111