Enumerate system disk drives (using the GetLogicalDriveStrings API function, System ("pause"); Very practical, but also use wcslen and other functions)

Source: Internet
Author: User

The code is as follows:

[CPP]View PlainCopy
  1. #include "stdafx.h"
  2. #include <vector>
  3. #include <string>
  4. #include <Windows.h>
  5. #include <tchar.h>
  6. int _tmain (int argc, _tchar* argv[])
  7. {
  8. TCHAR drives[128]; //Storage so drive name
  9. wchar_t* pdrive; //Drive pointer
  10. Std::vector<std::wstring> Strarray;
  11. //Get the first logical drive of the system
  12. if (! GetLogicalDriveStrings (sizeof (drives), drives))
  13. {
  14. printf ("failed to get drive \ r \ n");
  15. return false;
  16. }
  17. Pdrive = drives; //point to first logical drive
  18. //Put the drive character in the list box
  19. While (*pdrive)
  20. {
  21. //Add the drive name to the list
  22. Strarray.push_back (pdrive);
  23. //pointing to the next drive identifier
  24. Pdrive + = Wcslen (pdrive) + 1;
  25. }
  26. For (int i=0; i<strarray.size (); ++i)
  27. {
  28. printf ("%ls\r\n", Strarray[i].c_str ());
  29. }
  30. System ("pause");
  31. return 0;
  32. }

73649501

Enumerate system disk drives (using the GetLogicalDriveStrings API function, System ("pause"); Very practical, but also use wcslen and other functions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.