Portable way in C++ to get desktop resolution

There are several libraries helping you at getting the low-level stuff to work out. You'll probably need more stuff on those platforms anyways, so I'll list some:

  • SFML is a C++ library abstracting much of the I/O stuff, including display management. Also supports several platforms.
  • The classic SDL, although being a C library is widely used in platform independent game development and supports several platforms. Like SFML, it does more than just display management.
  • GLFW, see wardds answer, also a C library and also poses an abstraction layer, but more focused on display and keyboard/mouse I/O instead of broader I/O (audio etc.)

GLFW provides a crossplatform (for Windows, Mac, and Linux) way to get the desktop video mode. It is a C api, but it will work in C++. The relevant function (and documentation) is here:

void glfwGetDesktopMode( GLFWvidmode *mode )

Parameters

mode Pointer to a GLFWvidmode structure, which will be filled out by the function.

Return values

The GLFWvidmode structure pointed to by mode is filled out with the desktop video mode.

Description

This function returns the desktop video mode in a GLFWvidmode structure. See glfwGetVideoModes for a definition of the GLFWvidmode structure.

Notes

The color depth of the desktop display is always reported as the number of bits for each individual color component (red, green and blue), even if the desktop is not using an RGB or RGBA color format. For instance, an indexed 256 color display may report RedBits = 3, GreenBits = 3 and BlueBits = 2, which adds up to 8 bits in total.

The desktop video mode is the video mode used by the desktop at the time the GLFW window was opened, not the current video mode (which may differ from the desktop video mode if the GLFW window is a fullscreen window).

typedef struct {
  int Width, Height; // Video resolution
  int RedBits; // Number of red bits
  int GreenBits; // Number of green bits
  int BlueBits; // Number of blue bits
} GLFWvidmode;

See Jonas Wielicki's answer for alternatives.