wchar_t* Pfad;
wcin >> Pfad;
wchar_t* file = Pfad + "*.quiz";
Not working for me, how can I make this work? It says "*.quiz"
is wrong, something like it has to be a numeric value or something like that.
Well sorry, I am new to c++...
and my actual problem is, I use this, but I want to user to select the path
something like cin >> file
but I don't want the user to have to type "*.quiz";
wchar_t* file = L"C:/Users/Niku/Documents/Visual Studio 2012/Projects/Quiz/Quiz/Fragen_Niko/*.quiz";
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(file, &FindFileData);
if( hFind != INVALID_HANDLE_VALUE ) {
max++;
while ((x = FindNextFile(hFind, &FindFileData)) == TRUE)
max++;
}
If I use anything else besides wchar_t* it's not working..
It's not working the way you are expecting because you don't fully understand pointers and string literals in C++. If you want to know what's wrong, please pick any of these books (possibly beginner ones).
If you want to fix this problem straight ahead (take a shortcut) use an std::wstring
instead:
std::wstring Pfad;
std::wcin >> Pfad;
auto file = Pfad + L"*.quiz";
As suggested by Rook , if you have to pass a pointer to C APIs you can use the member function std::wstring::c_str
, which will return a const wchar_t*
for you to use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.