title: C++ Set Console Text Color in Windows from Static Method
body: <p>Is it possible to use a static method within a class to set the text color of a console for a Windows C++ application? My code looks like this:</p>
  
  <p><strong>Display.h:</strong></p>
  
  <pre><code>class Display {
  public:
    Display();
    static void setTextColor(int color);
  };
  </code></pre>
  
  <p><strong>Display.cpp:</strong></p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include "Display.h"
  
  void Display::setTextColor(int color) {
    HANDLE cHandle;
    cHandle = GetStdHandle(STD_OUTPUT_HANDLE);
  
    SetConsoleTextAttribute(cHandle, color);
  }
  </code></pre>
  
  <p><strong>main.cpp:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Display.h"
  
  int main(int argc, char *argv[]) {
    std::cout &lt;&lt; "HI"; //Outputs default color
    Display::setTextColor(9);
    std::cout &lt;&lt; "HI"; //Still default color
  
    return 0;
  }
  </code></pre>
  
  <p>Can anybody please explain why this static method will not update the text color? This excat code will work if placed inline.</p>
  
  <p>Thank you for your time.</p>