wstring未定义 [英] wstring is undefined

查看:128
本文介绍了wstring未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在得到错误,wstring未定义.这是什么罪魁祸首?如何解决?它就行了..... wstring sLastAccessTime;

I''m getting and error that wstring is undefined. What is cusing this? How can it be fixed? Its on the line.....wstring sLastAccessTime;

#include <string>
#include <vector>
#include <windows.h>
#include <time.h>
#include <map>

struct file_data 
{ 
    wstring sLastAccessTime; 
    __int64 nFileSize      ; 
}; 
 
int GetFileList(const wchar_t *searchkey, std::map<std::wstring, file_data> &map) 
{ 
    WIN32_FIND_DATA fd; 
    HANDLE h = FindFirstFile(searchkey,&fd); 
    if(h == INVALID_HANDLE_VALUE) 
    { 
        return 0; // no files found 
    } 
    while(1) 
    { 
        wchar_t buf[128]; 
        FILETIME ft = fd.ftLastWriteTime; 
        SYSTEMTIME sysTime; 
        FileTimeToSystemTime(&ft, &sysTime); 
        wsprintf(buf, L"%d-%02d-%02d",sysTime.wYear, sysTime.wMonth, sysTime.wDay); 
 
        file_data filedata; 
        filedata.sLastAccessTime= buf; 
        filedata.nFileSize      = (((__int64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow; 
 
        map[fd.cFileName]= filedata; 
 
        if (FindNextFile(h, &fd) == FALSE) 
            break; 
    } 
    return map.size(); 
} 
 
int main() 
{ 
    std::map<std::wstring, file_data> map; 
    GetFileList(L"C:\\Users\\DS\\Downloads\\*.zip", map); 
    GetFileList(L"C:\\Users\\DS\\Downloads\\*.txt", map); 
 
    for(std::map<std::wstring, file_data>::const_iterator it = map.begin(); 
        it != map.end(); ++it) 
    { 
        MessageBoxW(NULL,it->first.c_str(),L"File Name",MB_OK); 
        MessageBoxW(NULL,it->second.sLastAccessTime.c_str(),L"File Date",MB_OK); 
    } 
 
    return 0; 
}

推荐答案

就在我认为您做得很好的时候.在此其他答案线程中,如何获取文件数 [^ ]您正在使用几乎相同的程序.我们在那儿的讨论表明您已成功编译,运行并获取输出.该代码还使用wstring.

现在您在这里,询问为什么在代码中未定义wstring.更好的是,问问自己,自从早期的程序在哪里生效以来,您做了什么更改.显然,它并没有完全破坏,而是您在代码和/或构建中进行了更改.您会发现自己比在这里发布消息并等待几个小时才能做出响应要快得多.

因此,问题1不是不是为什么它不起作用,而是为什么它曾经起作用并且现在被破坏了.
Just when I thought you were doing so well. Over in this other answer thread How To Get A Count Of Files[^]You are using the almost identical program. Our discussion over there indicates that you were successfully compiling, running, and getting outputs. That code also uses wstring.

Now you''re over here, asking why wstring is undefined in the code. Better yet, ask yourself what you changed since the earlier program where it did work. Clearly, it didn''t break all by itself, you changed something in your code and/or build. You''d figure that out a lot quicker by yourself than posting messages over here and waiting hours for somebody to respond.

So, question 1 is not why it doesn''t work but why did it used to work and is now broken.


我认为您需要用std来限定类型.您已经完成了主要功能(即写入std::wstring).
I think that you need to qualify the type with std as you have done in main function (that is write std::wstring).


这篇关于wstring未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆