简体   繁体   English

如何使用_TCHAR *作为文件名打开文件? C / C ++

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

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! 谢谢!

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 . 如果没有定义宏UNICODE那么第二个将给出编译错误,也就是说,当TCHAR只是char而不是wchar_t

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM