According to MSDN [https://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes], when setting the console attribute, whichever property you don't set has a default value chosen.
Quote: "If no background constant is specified, the background is black, and if no foreground constant is specified, the text is black"
This is annoying if you have changed the default background color of your console and then use raw_ostrema to change the foreground color (or vice versa), because setting only the foreground attribute will also choose a default value for the background which will be different than your current console's setting.
This patch gets the current value of both attributes, and when you set one attribute, it sets the opposite attribute to its existing value before committing the color update.