error C2664: “strcmp”: 不能将参数 1 从“WCHAR [260]”转换为“const char *”

源程序:

#include   <iostream>
#include   <windows.h>
#include   <cstring>
using   namespace   std;

 

#define MAX_PATH 1028

void   ListFile(char*   szDir)
{

HANDLE     hFindFile;
WIN32_FIND_DATA     FileData;

char     szTempDir[MAX_PATH+1];
hFindFile   =   FindFirstFile(szTempDir,&FileData);

...

}

void main() {

   char       szPath[MAX_PATH+1];
   while(cin> > szPath)
   {
     if(szPath[strlen(szPath)-1]!= '\\ ')
     strcat(szPath, "\\ ");
     ListFile(szPath);
   }

}

error   C2664:   “strcmp”:   不能将参数   1   从“WCHAR   [260]”转换为“const   char   *”

 

解决方法:

1、vs2005   项目-> XXX属性-> 配置属性-> 常规-> 字符集 -> “使用unicode字符集” 改为   “未设置”  就去掉了unicode支持;(已经验证过

2、也可以在#include   <windows.h> 之前加上一句
#undef   UNICODE (未验证

3、你全部使用 TCHAR替换char
字符串常量用_T()括起来,如_T( "* ")(未验证

猜你喜欢

转载自blog.csdn.net/bruce135lee/article/details/80060834