c++ - 不显示逻辑盘符

标签 c++ c

我编写了一个小程序,可以搜索我 PC 中的所有逻辑驱动器,然后打印它们。但与我的预期不同,它没有显示它们。这是我的代码示例

TCHAR szDrive[] = (" A:");    
DWORD drive = GetLogicalDrives();
printf("The bitmask of the logical drives in hex: %0X\n", drive);
printf("The bitmask of the logical drives in decimal: %d\n", drive);
if(drive == 0)
    printf("GetLogicalDrives() failed with failure code: %d\n", GetLastError());
else
{
    printf("This machine has the following logical drives:\n");
    while(drive)
    {
    // Use the bitwise AND, 1â€"available, 0-not available
    if(drive & 1)
        printf("%S ", (const char *)szDrive);
    // increment, check next drive
    ++szDrive[1];
    // shift the bitmask binary right
    drive >>= 1;
}
printf("\n ");
}  

最佳答案

您的 printf 语句已损坏。使用这个:

printf("%s ", szDrive);

我猜你使用 %S 而不是 %s 只是一个拼写错误。

关于c++ - 不显示逻辑盘符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18100836/

相关文章:

c++ - 正则表达式替换为c++ 11中的回调?

C 无关函数似乎影响简单的数组初始化

c - Qsort 不排序 char * 数组

c++ - 数组类型的元素类型不完整,无法进行模式匹配

c++ - 结构包装重复

c++ - 查找 shared_ptr 的引用计数增加的位置

c# - 将文件从一个项目复制到另一个项目时出错

c++ - 我可以在 C++ 运行时初始化静态 const 成员吗?

java - 为什么 C 和 Java 对以下循环的处理方式不同

c - 循环遍历数组,增量不起作用