我被要求为现有的旧项目添加功能,但我无法构建它。它处理 unicode 字符串,但我在使用 TCHAR 时遇到很多错误。具体来说,几乎每个错误都是 TCHAR 无法转换为或用作 wchar_t。从我在许多不同的文章中看到的情况来看,我尝试使用#define _UNICODE 或#define UNICODE,但它们都没有解决问题。
这是一段代码:
#include <windows.h>
#include <wininet.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
#include <strsafe.h>
#include <string>
#include <list>
#include <cctype>
#include <winnt.h>
#include <atlconv.h>
#pragma comment(lib,"wininet.lib")
using namespace std;
TCHAR *tags[] = { _T("aa"), _T("bb"), _T("cc"),
NULL };
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
for (i = 1; i<argc; i++) {
if (wcscmp(argv[i], _T("-h")) == 0) {
...
}
else if (wcscmp(argv[i], _T("-f")) == 0) {
...
}
...
}
例如,在上面的行中,当使用 wcscmp 时,我得到
argument of type "_TCHAR *" is incompatible with parameter of type "const wchar_t *"
关于 argv[i]
和
argument of type "const char *" is incompatible with parameter of type "const wchar_t *"
关于 _T("-h")。
任何建议将不胜感激。