-1

文字列 si の代わりに文字列 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");
}
4

1 に答える 1

4

std::stringへの暗黙的な変換はありませんconst char*c_str()のメンバ関数を呼び出して、ポインタを手動で取得する必要がありますstd::string

void * handle = FindFirstFile( s.c_str(), &fData );

Microsoft の Unicode の考え方に変更しても役に立ちません。using に切り替える必要があり、文字列バッファーへの生のポインターを取得するためstd::wstringに呼び出す必要があります。c_str()

さまざまな文字列とその操作について詳しくは、 cppreference.comを参照してください。

于 2013-04-17T03:00:01.360 に答える