开发者

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

开发者 https://www.devze.com 2023-02-18 01:27 出处:网络
My main has the following signature: int _tm开发者_如何学JAVAain(int argc, _TCHAR* argv[]) I would like to preform the following:

My main has the following signature:

int _tm开发者_如何学JAVAain(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!


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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号