Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c+;中FindFirstFile()出现错误C2664+;_C++_File - Fatal编程技术网

C++ c+;中FindFirstFile()出现错误C2664+;

C++ c+;中FindFirstFile()出现错误C2664+;,c++,file,C++,File,这里的箭头是,如果我不写字符串s,而是写存储在字符串s中的内容(“C:/Users/John/Desktop/mama/*”),它工作得很好,但我需要这样使用它,因为我将从用户那里获取路径。我怎样才能使它与字符串一起工作?错误:错误1错误C2664:“FindFirstFileA”:无法将参数1从“std::string”转换为“LPCSTR” 同样在这个错误之前,出现了另一个类似的错误,我将字符集从Unicode更改为Not set以使其正常工作。这个改变会给我的主要项目带来麻烦吗?这是一个测

这里的箭头是,如果我不写字符串s,而是写存储在字符串s中的内容(“C:/Users/John/Desktop/mama/*”),它工作得很好,但我需要这样使用它,因为我将从用户那里获取路径。我怎样才能使它与字符串一起工作?错误:错误1错误C2664:“FindFirstFileA”:无法将参数1从“std::string”转换为“LPCSTR”

同样在这个错误之前,出现了另一个类似的错误,我将字符集从Unicode更改为Not set以使其正常工作。这个改变会给我的主要项目带来麻烦吗?这是一个测试,当它将是确定的,我将添加到我的哈希表项目! 感谢您抽出时间:)

#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
结构路径名
{
字符串路径;
路径名*下一步;
};
int main()
{
路径名*head=新路径名;
路径名*temp=head;
WIN32_FIND_DATA fData;
字符串s=“C:/Users/John/Desktop/mama/*”;
void*handle=FindFirstFile(s,&fData);//下一步=0;
temp->path=fData.cFileName;
while(FindNextFile(handle,&fData)!=0)//swsto清单
{   
temp->next=新路径名;
温度=温度->下一步;
温度->下一步=0;
temp->path=fData.cFileName;
}
温度=水头;

cout
std::string
没有到
const char*
的隐式转换。您必须通过调用
std::string
c_str()
成员函数手动检索指针

void * handle = FindFirstFile( s.c_str(), &fData );
更改为Microsoft的Unicode不会有帮助。您必须切换到使用
std::wstring
,并且仍然需要调用
c_str()
来检索字符串缓冲区的原始指针


你可以在

上找到更多关于各种字符串及其操作的信息。我真的应该保留一个
std::string
LPCSTR
问题的书签。问题太多了。值得一提的是,当我搜索“[c++]std::string到c-string”时,第一个出现的问题是我回答的:p()
void * handle = FindFirstFile( s.c_str(), &fData );