Home > Back-end >  Considering that std::cout is an initialized object, why does visual studio 'not recognise its
Considering that std::cout is an initialized object, why does visual studio 'not recognise its

Time:09-22

Considering that std::cout is an initialized object, why does visual studio 'not recognise its identifier' whilst setting a Watch in the debugger?

How do I view this object in memory?

Setting both std::cout and cout as watch variables returns:

[identifier "std::cout" is undefined]

[identifier "cout" is undefined]

respectively.

#include <iostream>

int main()
{
    std::cout << "Usage of std::cout\n";

    // breakpoint
    return 0;
}

According to https://en.cppreference.com/w/cpp/io/cout on the topic of cout:

These objects are guaranteed to be initialized during or before the first time an object of type std::ios_base::Init is constructed and are available for use in the constructors and destructors of static objects with ordered initialization (as long as <iostream> is included before the object is defined).

CodePudding user response:

you could create a local reference to std::cout and add a watch for that. E.g.:

auto& mycout = std::cout;
  • Related