pisya

Untitled

Feb 28th, 2021
653
125 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <fileapi.h>
  4. #include <bitset>
  5.  
  6. using namespace std;
  7.  
  8. void printStringDisks();
  9. void GetStringsDisksVariant2();
  10. int decToBin(int num);
  11.  
  12. int main()
  13. {
  14.     setlocale(LC_ALL, "Russian");
  15.  
  16.     printStringDisks();
  17.     GetStringsDisksVariant2();
  18.  
  19.     decToBin(123);
  20. }
  21.  
  22. void printStringDisks() {
  23.     DWORD driversMask = GetLogicalDrives();
  24.  
  25.     char disk[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
  26.  
  27.     string maskBit = bitset<sizeof(disk)>(driversMask).to_string();
  28.     reverse(maskBit.begin(), maskBit.end());
  29.  
  30.     for (size_t i = 0; i < maskBit.size(); i++) {
  31.         if (maskBit[i] == '1')
  32.             cout << disk[i] << " ";
  33.     }
  34.     cout << endl;
  35. }
  36.  
  37. void GetStringsDisksVariant2()
  38. {
  39.     cout << "Получение данных по дискам (GetLogicalDriveStringsW)\n";
  40.     wchar_t buffer[128];
  41.     DWORD sizeBuffer = sizeof(buffer) / sizeof(wchar_t) - 1;
  42.     DWORD result = GetLogicalDriveStringsW(sizeBuffer, buffer);
  43.  
  44.     wchar_t* it = buffer;
  45.     wchar_t* end = buffer + (result > sizeof(buffer) ? sizeof(buffer) : result);
  46.  
  47.     while (it < end)
  48.     {
  49.         wstring disk;
  50.         while (it < end && *it) disk += *it++;
  51.         wcout << disk << ' ';
  52.         it++;
  53.     }
  54. }
  55.  
  56.  
  57. int decToBin(int num)
  58. {
  59.     int initialNum = num, bin = 0, k = 1;
  60.  
  61.     while (num)
  62.     {
  63.         bin += (num % 2) * k;
  64.         k *= 10;
  65.         num /= 2;
  66.     }
  67.  
  68.     return bin;
  69. }
  70.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×