I ahve the following piece of code. I get a correctly filled vector. But I am unable to print or use the vector contents which are file names from a directory. As soon as I do e
search_data.cFileName
is a pointer to memory controlled by the FindFirstFile
/FindNextFile
iterator interface; you cannot store this pointer value as the pointed-to memory could change from iteration to iteration (or even be freed after the iteration completes).
Instead, you must make a copy of the string to put in your vector, e.g. using wcsdup
. Even better, define your vector as a vector
, so that push_back(search_data.cFileName);
creates a wstring
with the contents of search_data.cFileName
.