C++ Add string to const char* array

  append, arrays, c++

Hey so this is probably a dumb beginner question.

I want to write the filename of all .txt files from a folder inside a const char* array[].

So I tried to do it like this:

const char* locations[] = {"1"};
bool x = true;
int i = 0;    

LPCSTR file = "C:/Folder/*.txt";
WIN32_FIND_DATA FindFileData;

HANDLE hFind;
hFind = FindFirstFile(file, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
    do 
    {
        locations.append(FindFileData.cFileName); //Gives an error
        i++;
    }
    while (FindNextFile(hFind, &FindFileData));
    FindClose(hFind);
}
cout << "number of files " << i << endl;

Basically the code should add the Filename of the .txt file to the const char* locations array but it doesn’t work using append as it gives me the error: "C++ expression must have class type but it has type ”const char *”"

So how do I do it right?

Source: Windows Questions C++

LEAVE A COMMENT