c++中的FindFirstFile()错误C2664
Error C2664 with FindFirstFile() in c++
箭头是如果不是字符串s我写什么是存储在字符串s ("C:/Users/John/Desktop/mama/*"),它工作得很好,但我需要这样使用它,因为我将从用户获得路径。我怎么能使它与字符串的工作?错误:错误1错误C2664: 'FindFirstFileA':无法将参数1从'std::string'转换为'LPCSTR'
同样在此错误之前出现了另一个类似的错误,我将字符集从Unicode更改为Not set以使其工作。这个变化会给我的主要项目带来麻烦吗?这是一个测试,当它将是好的,我会把它添加到我的哈希表项目!谢谢你的时间:)
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <tchar.h>
#include <stdio.h>
using namespace std;
struct pathname
{
string path;
pathname *next;
};
int main()
{
pathname *head = new pathname;
pathname *temp = head;
WIN32_FIND_DATA fData;
string s = "C:/Users/John/Desktop/mama/*";
void * handle = FindFirstFile( s, &fData ); //<~~~~~~
FindNextFile(handle, &fData);//meta apo auto emfanizei ta onomata
FindNextFile(handle, &fData);
temp->next = 0;
temp->path = fData.cFileName;
while (FindNextFile(handle, &fData) != 0) //swsto listing
{
temp->next = new pathname;
temp = temp->next;
temp->next = 0;
temp->path = fData.cFileName;
}
temp = head;
cout <<"edw arxizei" <<endl;
while(temp != 0)
{
cout << temp->path << endl;
temp = temp->next;
}
system("pause");
}
std::string
没有到const char*
的隐式转换。您必须通过调用std::string
的c_str()
成员函数手动检索指针。
void * handle = FindFirstFile( s.c_str(), &fData );
使用微软的Unicode是没有用的。你必须切换到使用std::wstring
,并且仍然必须调用c_str()
来检索指向字符串缓冲区的原始指针。
您可以在cppreference.com上找到更多关于各种字符串及其操作的信息
相关文章:
- 使用解算器SparseLU并获得错误C2664
- VS 2017 错误 C2664 地图插入尝试
- 使用自定义对象声明shared_ptr数组时出现错误 C2664
- 编译器错误 C2664 使用 std::map 和自定义类作为其值
- 如何在 VC++ 中通过引用传递另一个对象的方法(错误 C2664)
- 在C++中构造模板函数时出现编译错误 C2664 和 C2440
- 了解错误 C2664:无法转换参数 1
- 错误 C2664:无法从'NvPhysicalGpuHandle'转换参数 1
- 错误 C2664 和 E0167 被难倒
- 尝试创建unique_ptr时出现错误 C2664
- 错误 C2664:"errno_t wcstombs_s(size_t *,字符 *,size_t,常量 wchar_t *,size_t)":无法转换参数 4
- 错误C2664:无法转换参数错误
- 在集合中转换为小写 C++ 错误 C2664
- 错误 C2664:无法将参数 1 从 'int' 转换为 'int []'
- 将互斥锁数组传递给函数时出现错误 C2664
- 错误 C2664:"发送":无法将参数 2 从"服务器问候语"转换为"常量字符 *"
- 错误C2664:无法转换参数(指纹传感器检测)
- C++ 错误 1 错误 C2664 传递数组指针
- 错误 C2664:'CComboBox::InsertString':无法将参数 2 从 'const char [4]' 转换为 'LPCTSTR'
- 创建面向对象的链表时出现编译问题(编译器错误C2664)