システムで使用可能なドライブを引き出して、ドライブに関するさまざまな情報を出力するプログラムの 1 つについて助けが必要です。私は VC++ を使用しており、C++ にはかなり慣れていないため、経験豊富なプログラマーからの高レベルの入力またはサンプル コードが必要です。
ここに私の現在のソースコードがあります:
#include "stdafx.h"
#include Windows.h
#include stdio.h
#include iostream
using namespace std;
int main()
{
// Initial Dummy drive
WCHAR myDrives[] = L" A";
// Get the logical drive bitmask (1st drive at bit position 0, 2nd drive at bit position 1... so on)
DWORD myDrivesBitMask = GetLogicalDrives();
// Verifying the returned drive mask
if(myDrivesBitMask == 0)
wprintf(L"GetLogicalDrives() failed with error code: %d\n", GetLastError());
else {
wprintf(L"This machine has the following logical drives:\n");
while(myDrivesBitMask) {
// Use the bitwise AND with 1 to identify
// whether there is a drive present or not.
if(myDrivesBitMask & 1) {
// Printing out the available drives
wprintf(L"drive %s\n", myDrives);
}
// increment counter for the next available drive.
myDrives[1]++;
// shift the bitmask binary right
myDrivesBitMask >>= 1;
}
wprintf(L"\n");
}
system("pause");
}
` -ここに出力があります-
This machine has the following logical drives:
drive C
drive D
drive E
drive F
drive G
drive H
drive I
各ドライブに関する追加情報を出力する必要があります (おそらく、例を使用すると、短い時間でストーリーを説明できます)。
ドライブ – C:\ ドライブ タイプ: Fixed Drive Ready Status: True ボリューム ラベル: ブート ドライブ ファイル システム タイプ: NTFS 空き容量: 30021926912 合計ドライブ サイズ: 240055742464
ドライブ – D:\ ドライブ タイプ: Fixed Drive Ready Status: True Volume Label: Application Data File System Type: NTFS Free Space: 42462507008 ドライブの合計サイズ: 240054693888
ドライブの種類、ドライブの状態、ボリューム ラベル、ファイル システムの種類、空き容量、ドライブの合計サイズを取得するには、どの方法、libs api などを使用できますか?
*余談ですが、プリプロセッサ ディレクティブ、特に標準 I/O ヘッダー ファイル内に欠陥があることに気付きました。printfを使用することは推奨される方法ではなく、coutはタイプセーフであり、適切なルートであることはわかっていますが、coutで出力をフォーマットする方法がわかりませんでしたwprintf(L"drive %s\n", myDrives);.... so how would you do this with cout??
前もって感謝します。