IntelliSense: 未定义标识符 "wsprintf" 求助大神

captain堂吉诃德 2017-07-05 04:09:57
在实现寻找文件夹下的子文件过程中,出现了 IntelliSense: 未定义标识符 "wsprintf" 问题,之前用过这个函数,还是正常的,现在复制过来直接用的,就不行了,望大神们给点建议,谢谢啦!
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define LEN 1024

vector<string> DirectoryList(LPCSTR PATH)
{
vector<string> address;

WIN32_FIND_DATA FindData;
HANDLE hError;
int FileCount = 0;
char FilePathName[LEN];
// 构造路径
char FullPathName[LEN];
strcpy_s(FilePathName, PATH);
strcat_s(FilePathName, "\\*.*");
hError = FindFirstFile(FilePathName, &FindData);
if (hError == INVALID_HANDLE_VALUE)
{
printf("搜索失败!");

}

//char f[200]; //ggggggaaaaiiiii
//f = (char*)malloc(40 * sizeof(char));


while (::FindNextFile(hError, &FindData))
{
// 过虑.和..
if (strcmp(FindData.cFileName, ".") == 0
|| strcmp(FindData.cFileName, "..") == 0)
{
continue;
//return 0;
}
// 构造完整路径
wsprintf(FullPathName, "%s\\%s", PATH, FindData.cFileName);
FileCount++;
// 输出本级的文件
printf("\n%d %s \n", FileCount, FullPathName);

/*
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
printf("<Dir>");
DirectoryList(FullPathName);
}
*/
address.push_back(FullPathName);

}
//cout << address.size() << endl;


return address;
}
...全文
827 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Really_want 2017-07-06
  • 打赏
  • 举报
回复
wsprinf 是wchar_t版本的sprintf,而你传入的参数FullPathName是char类型的,显然不匹配。
回到你关心的问题,未定义标识符。你知道wsprintf函数的声明在什么文件吗?包含进来就好了。
  • 打赏
  • 举报
回复
我设置了多字节字符集,我刚发现我注释掉一个头文件后,错误就消失了,这是文件相互包含的问题吗?这是我注释掉的头文件: #include "facedetect-dll.h"
赵4老师 2017-07-05
  • 打赏
  • 举报
回复
项目设置使用多字节字符集。 #pragma warning(disable:4996) …… sprintf(FullPathName, "%s\\%s", PATH, FindData.cFileName);
幻夢之葉 2017-07-05
  • 打赏
  • 举报
回复
ASCII 和 Unicode的通用版本

#include <windows.h>
#include <tchar.h>
#include <cstdio>
#include <vector>
#include <string>
#define LEN 1024

using namespace std;

#ifdef _UNICODE
typedef wstring TSTRING;
#else
typedef string TSTRING;
#endif

vector<TSTRING>  DirectoryList(LPCTSTR PATH)
{
    vector<TSTRING> address;

    WIN32_FIND_DATA FindData;
    HANDLE hError;
    int FileCount = 0;
    TCHAR FilePathName[LEN];
    // 构造路径
    TCHAR FullPathName[LEN];
    _tcscpy(FilePathName, PATH);
    _tcscpy(FilePathName, _T("\\*.*"));
    hError = FindFirstFile(FilePathName, &FindData);
    if (hError == INVALID_HANDLE_VALUE)
    {
        printf("搜索失败!");

    }

    //char f[200];                                    //ggggggaaaaiiiii
    //f = (char*)malloc(40 * sizeof(char));


    while (::FindNextFile(hError, &FindData))
    {
        // 过虑.和..
        if (_tcscmp(FindData.cFileName, _T(".")) == 0
            || _tcscmp(FindData.cFileName, _T("..")) == 0)
        {
            continue;
            //return 0;
        }
        // 构造完整路径
        wsprintf(FullPathName, _T("%s\\%s"), PATH, FindData.cFileName);
        FileCount++;
        // 输出本级的文件
        printf("\n%d  %s  \n", FileCount, FullPathName);

        /*
        if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
        printf("<Dir>");
        DirectoryList(FullPathName);
        }
        */
        address.push_back(FullPathName);

    }
    //cout << address.size() << endl;


    return address;
}

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧