0

i am tring to use c++ to get display device info ,but cout give me some memory address ,how can i get string value ? output like :00CFF4B4:00CFF5F8, i am using visual studio 2019

#include <iostream>
#include <windows.h>

int main()
{
    DISPLAY_DEVICE d;
    d.cb = sizeof(DISPLAY_DEVICE);
    int device_num = 0;

    while (EnumDisplayDevices(NULL, device_num, &d, 0))
    {
        std::cout << d.DeviceName << ":" << d.DeviceID<<std::endl;
        device_num++;
    }
    return 0;

}
JaMiT
  • 14,422
  • 4
  • 15
  • 31

1 Answers1

1

I'm assuming you're using the W version of DISPLAY_DEVICE (DISPLAY_DEVICEW) which I believe is the default since at least Visual Studio 2015 and later (the compiler defines UNICODE).

The DeviceName and DeviceID members of DISPLAY_DEVICEW are WCHAR (a macro for wchar_t), so you need to use wcout instead of cout:

std::wcout << d.DeviceName << ":" << d.DeviceID << std::endl;
Dai
  • 141,631
  • 28
  • 261
  • 374
  • this ansower is correct ,but i am not understand why it works like so ,why not visual studio pop up an error to tell me but just give me an memory address ? – huaicheng pan Sep 18 '19 at 04:15