c++ - How to use WriteConsoleOutputAttribute function correctly -


why following code

  const std::string text = "str";    handle stdout_handle = getstdhandle(std_output_handle);    coord coords = { 0, 0 };   dword written = 0;   writeconsoleoutputcharactera(stdout_handle, text.c_str(), text.size(), coords, &written);    word attributes = foreground_green;   writeconsoleoutputattribute(stdout_handle, &attributes, text.size(), coords, &written); 

results in this:

enter image description here

what doing wrong? how can fix it?

&attributes points array of length one, single green attribute. claim array text.size() long. result, copy random stack content next 2 cells. happens red-on-red.

solution:

std::vector<word> attributes(text.size(), foreground_green); writeconsoleoutputattribute(stdout_handle, &attributes[0] ... 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -