The code is as follows:
[CPP]View PlainCopy
- #include "stdafx.h"
- #include <vector>
- #include <string>
- #include <Windows.h>
- #include <tchar.h>
- int _tmain (int argc, _tchar* argv[])
- {
- TCHAR drives[128]; //Storage so drive name
- wchar_t* pdrive; //Drive pointer
- Std::vector<std::wstring> Strarray;
- //Get the first logical drive of the system
- if (! GetLogicalDriveStrings (sizeof (drives), drives))
- {
- printf ("failed to get drive \ r \ n");
- return false;
- }
- Pdrive = drives; //point to first logical drive
- //Put the drive character in the list box
- While (*pdrive)
- {
- //Add the drive name to the list
- Strarray.push_back (pdrive);
- //pointing to the next drive identifier
- Pdrive + = Wcslen (pdrive) + 1;
- }
- For (int i=0; i<strarray.size (); ++i)
- {
- printf ("%ls\r\n", Strarray[i].c_str ());
- }
- System ("pause");
- return 0;
- }
73649501
Enumerate system disk drives (using the GetLogicalDriveStrings API function, System ("pause"); Very practical, but also use wcslen and other functions)