1

code

Hello. I have these lines of code in the image above. The second line prints the address. But I like to print the value of this address e.g. "Microsoft Loopback Adapter".

How to do that?

Community
  • 1
  • 1
moobi
  • 7,849
  • 2
  • 18
  • 29
  • 1
    `PWCHAR` is a `short` pointer and not a `char` pointer. So `cout` does not treat it as a pointer to a null-terminated string, and prints the value of that pointer instead of the contents of the pointed string. – barak manos Aug 25 '14 at 13:22
  • 1
    You're welcome. Good point in asking this question, and the answer below is also good. – barak manos Aug 25 '14 at 13:27

1 Answers1

3

Try using std::wcout:

std::wcout << description << std::endl;

cout prints the pointer value of description as it does not treat description as a pointer to a null terminated string.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • It's worth mentioning the difference between `PWCHAR` and `char*`, which yields the different behavior of `ofstream::operator>>` for each one of them. – barak manos Aug 25 '14 at 13:25
  • Also note that char * use the current code page ie, pointer to an ANSI strings whereas WCHAR APIs use UTF-16 – Rahul Tripathi Aug 25 '14 at 13:30