{"id":143,"date":"2008-11-28T02:53:56","date_gmt":"2008-11-28T00:53:56","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=143"},"modified":"2013-08-21T11:12:53","modified_gmt":"2013-08-21T09:12:53","slug":"helper-class-for-console-functions","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/","title":{"rendered":"Helper Class for Console Functions"},"content":{"rendered":"<p>Have you tried to print colored text in a console or put the text at a specific position? You know then that STL or CRT does not provide that functionality.<br \/>\nWindows API however, contains a set of functions for working with console windows. The list of these functions is available in <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms682073(VS.85).aspx\" target=\"_blank\">MSDN<\/a>.<\/p>\n<p>However, to simplify the use of these functions I have created a template, wrapper class that provides methods and overloaded operators to:<\/p>\n<ul>\n<li>change the color for text and background<\/li>\n<li>set the cursor position<\/li>\n<li>write to the console<\/li>\n<li>read from the console<\/li>\n<\/ul>\n<p>The class is called basic_console, and is a template class. There are two specializations, one for ANSI, called console, and one for UNICODE, called wconsole.<\/p>\n<pre class=\"prettyprint\">\r\ntypedef basic_console&lt; char, std::char_traits&lt; char &gt;&gt; console;\r\ntypedef basic_console&lt; wchar_t, std::char_traits&lt; wchar_t &gt;&gt; wconsole;\r\n<\/pre>\n<p>You can change the position on both horizontal and vertical or on only one of the two:<\/p>\n<pre class=\"prettyprint\">\r\n   void GoTo(int x, int y)\r\n   void GoToX(int x)\r\n   void GoToY(int y)\r\n   console_pos GetConsolePos()\r\n<\/pre>\n<p>There is also an overloaded operator for changing the position, specified with a console_pos structure.<\/p>\n<pre class=\"prettyprint\">\r\n\t_Myt&amp; operator&lt;&lt;(const console_pos&amp; pos)\r\n<\/pre>\n<p>For the color, you can change the text and background color, using one of these functions:<\/p>\n<pre class=\"prettyprint\">\r\n   void SetForeColor(text_color::Color crText)\r\n   void SetBackColor(bg_color::Color crBack)\r\n   void SetColors(text_color::Color crText, bg_color::Color crBack)\r\n   void SetColors(WORD colors)\r\n   void SetColors(WORD crText, WORD crBack)\r\n   void UseDefaultColors()\r\n   \r\n   _Myt&amp; operator&lt;&lt;(const console_colors&amp; col)\r\n<\/pre>\n<p>Number of colors are limited, but we can combine them to produce more. Windows defines separate flags for the text and background colors.<br \/>\nI have created two classes text_color and back_color to define mnemonics for colors based on these flags.<\/p>\n<pre class=\"prettyprint\">\r\nclass text_color\r\n{\r\npublic:\r\n\tenum Color\r\n\t{\r\n\t\tBlack = 0,\r\n\t\tWhite = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,\r\n\t\tBlue = FOREGROUND_BLUE,\r\n\t\tGreen = FOREGROUND_GREEN,\r\n\t\tRed = FOREGROUND_RED,\r\n\t\tYellow = FOREGROUND_RED | FOREGROUND_GREEN,\r\n\t\tMagenta = FOREGROUND_RED | FOREGROUND_BLUE,\r\n\t\tLightWhite = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY,\r\n\t\tLightBlue = FOREGROUND_BLUE | FOREGROUND_INTENSITY,\r\n\t\tLightGreen = FOREGROUND_GREEN | FOREGROUND_INTENSITY,\r\n\t\tLightRed = FOREGROUND_RED | FOREGROUND_INTENSITY,\r\n\t\tLightYellow = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,\r\n\t\tLightMagenta = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,\r\n\t};\r\n};\r\n\r\nclass bg_color\r\n{\r\npublic:\r\n\tenum Color\r\n\t{\r\n\t\tBlack = 0,\r\n\t\tWhite = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED,\r\n\t\tBlue = BACKGROUND_BLUE,\r\n\t\tGreen = BACKGROUND_GREEN,\r\n\t\tRed = BACKGROUND_RED,\r\n\t\tYellow = BACKGROUND_RED | BACKGROUND_GREEN,\r\n\t\tMagenta = BACKGROUND_RED | BACKGROUND_BLUE,\r\n\t\tLightWhite = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY,\r\n\t\tLightBlue = BACKGROUND_BLUE | BACKGROUND_INTENSITY,\r\n\t\tLightGreen = BACKGROUND_GREEN | BACKGROUND_INTENSITY,\r\n\t\tLightRed = BACKGROUND_RED | BACKGROUND_INTENSITY,\r\n\t\tLightYellow = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY,\r\n\t\tLightMagenta = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY,\r\n\t};\r\n};\r\n<\/pre>\n<p>Let&#8217;s see several examples. The first one, shows how to print text with different colors. Moreover, the colored text is always displayed starting with column 40.<\/p>\n<pre class=\"prettyprint\">\r\nint main()\r\n{\r\n   console con;\r\n\r\n   con.SetForeColor(text_color::White);\r\n   con &lt;&lt; \"Processing with files\";\r\n   con.GoToX(40);\r\n   con &lt;&lt; \"OK\" &lt;&lt; \"\\n\";\r\n\r\n   con.SetForeColor(text_color::White);\r\n   con &lt;&lt; \"Looking for templates\";\r\n   con.GoToX(40);\r\n   con.SetForeColor(text_color::LightYellow);\r\n   con &lt;&lt; \"Not found\" &lt;&lt; \"\\n\";\r\n\r\n   con.SetForeColor(text_color::White);\r\n   con &lt;&lt; \"Creating new account\";\r\n   con.GoToX(40);\r\n   con.SetForeColor(text_color::LightRed);\r\n   con &lt;&lt; \"Failed\" &lt;&lt; \"\\n\";\r\n   \r\n   return 0;\r\n}\r\n<\/pre>\n<p>Here is the output for this program<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.mariusbancila.ro\/blog\/wp-content\/uploads\/2008\/11\/console1.png\"><\/p>\n<p>A second example shows how to print numbers starting from 1 to N and back to 1 to form a rhomb.<\/p>\n<pre class=\"prettyprint\">\r\nint main()\r\n{\r\n   console con;\r\n\r\n   int depth;\r\n   con &lt;&lt; \"Depth (1-9)? \";\r\n   con &gt;&gt; depth;\r\n\r\n   int middle = 20;\r\n   for(int i = 1; i &lt;= depth; ++i)\r\n   {\r\n      con.GoToX(middle-i+1);\r\n      for(int j = 1; j&lt;=i; ++j)\r\n      {\r\n         con &lt;&lt; i &lt;&lt; \" \";\r\n      }\r\n      con &lt;&lt; \"\\n\";\r\n   }\r\n   for(int i = depth-1; i &gt;=1; --i)\r\n   {\r\n      con.GoToX(middle-i+1);\r\n      for(int j = 1; j&lt;=i; ++j)\r\n      {\r\n         con &lt;&lt; i &lt;&lt; \" \";\r\n      }\r\n      con &lt;&lt; \"\\n\";\r\n   }\r\n   \r\n   return 0;\r\n}\r\n<\/pre>\n<p>And here is the output, when the selected depth is 9:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.mariusbancila.ro\/blog\/wp-content\/uploads\/2008\/11\/console2.png\"><\/p>\n<p>The same can be achived using the overloaded operator&lt;&lt; for console_pos.<\/p>\n<pre class=\"prettyprint\">\r\nint main()\r\n{\r\n   console con;\r\n\r\n   int depth;\r\n   con &lt;&lt; \"Depth (1-9)? \";\r\n   con >> depth;\r\n\r\n   int x = 20;\r\n   int y = 2;\r\n   for(int i = 1; i &lt;= depth; ++i)\r\n   {\r\n      con &lt;&lt; console_pos(x-i+1, y++);\r\n      for(int j = 1; j&lt;=i; ++j)\r\n      {\r\n         con &lt;&lt; i &lt;&lt; \" \";\r\n      }\r\n   }\r\n   for(int i = depth-1; i &gt;=1; --i)\r\n   {\r\n      con &lt;&lt; console_pos(x-i+1, y++);\r\n      for(int j = 1; j&lt;=i; ++j)\r\n      {\r\n         con &lt;&lt; i &lt;&lt; \" \";\r\n      }\r\n   }\r\n   \r\n   return 0;\r\n}\r\n<\/pre>\n<p>A third and last examples shows how to read a matrix on rows and columns.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.mariusbancila.ro\/blog\/wp-content\/uploads\/2008\/11\/console3.png\"><\/p>\n<pre class=\"prettyprint\">\r\nint main()\r\n{\r\n   console con;\r\n\r\n   int rows;\r\n   int cols;\r\n\r\n   con &lt;&lt; \"rows: \"; con &gt;&gt; rows;\r\n   con &lt;&lt; \"cols: \"; con &gt;&gt; cols;\r\n\r\n   std::vector&lt; int &gt; numbers;\r\n\r\n   for(int i = 0; i &lt; rows; ++i)\r\n   {\r\n      for(int j = 0; j &lt; cols; ++j)\r\n      {\r\n         con.GoTo(j*4, i+2);\r\n         con &lt;&lt; \"[_]\";\r\n      }\r\n   }\r\n   int val;\r\n   for(int i = 0; i &lt; rows; ++i)\r\n   {\r\n      for(int j = 0; j &lt; cols; ++j)\r\n      {\r\n         con.GoTo(j*4+1, i+2);\r\n         con &gt;&gt; val;\r\n         numbers.push_back(val);\r\n      }\r\n   }\r\n   \r\n   return 0;\r\n}\r\n<\/pre>\n<p>Of course, this basic_console class does not carry all the possible functionality you can imagine, but it should be good enough for basic operations.<\/p>\n<p><a href=\"http:\/\/www.mariusbancila.ro\/blog\/wp-content\/uploads\/2008\/11\/Console.h\">Here<\/a> is the file with the source code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you tried to print colored text in a console or put the text at a specific position? You know then that STL or CRT does not provide that functionality. Windows API however, contains a set of functions for working with console windows. The list of these functions is available in MSDN. However, to simplify &#8230; <a title=\"Helper Class for Console Functions\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/\" aria-label=\"Read more about Helper Class for Console Functions\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,8],"tags":[451,94,459],"class_list":["post-143","post","type-post","status-publish","format-standard","hentry","category-c","category-windows-programming","tag-c","tag-console","tag-windows"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Helper class for printing to the console.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,console,windows\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Helper Class for Console Functions\" \/>\n\t\t<meta property=\"og:description\" content=\"Helper class for printing to the console.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-11-28T00:53:56+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2013-08-21T09:12:53+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Helper Class for Console Functions\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Helper class for printing to the console.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#article\",\"name\":\"Helper Class for Console Functions\",\"headline\":\"Helper Class for Console Functions\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"http:\\\/\\\/www.mariusbancila.ro\\\/blog\\\/wp-content\\\/uploads\\\/2008\\\/11\\\/console1.png\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#articleImage\"},\"datePublished\":\"2008-11-28T02:53:56+02:00\",\"dateModified\":\"2013-08-21T11:12:53+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":8,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#webpage\"},\"articleSection\":\"C++, Windows Programming, C++, console, Windows\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#listItem\",\"name\":\"Helper Class for Console Functions\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#listItem\",\"position\":5,\"name\":\"Helper Class for Console Functions\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/\",\"name\":\"Helper Class for Console Functions\",\"description\":\"Helper class for printing to the console.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/11\\\/28\\\/helper-class-for-console-functions\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2008-11-28T02:53:56+02:00\",\"dateModified\":\"2013-08-21T11:12:53+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Helper Class for Console Functions","description":"Helper class for printing to the console.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/","robots":"max-image-preview:large","keywords":"c++,console,windows","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#article","name":"Helper Class for Console Functions","headline":"Helper Class for Console Functions","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"http:\/\/www.mariusbancila.ro\/blog\/wp-content\/uploads\/2008\/11\/console1.png","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#articleImage"},"datePublished":"2008-11-28T02:53:56+02:00","dateModified":"2013-08-21T11:12:53+02:00","inLanguage":"en-US","commentCount":8,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#webpage"},"articleSection":"C++, Windows Programming, C++, console, Windows"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#listItem","name":"Helper Class for Console Functions"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#listItem","position":5,"name":"Helper Class for Console Functions","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/","name":"Helper Class for Console Functions","description":"Helper class for printing to the console.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2008-11-28T02:53:56+02:00","dateModified":"2013-08-21T11:12:53+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Helper Class for Console Functions","og:description":"Helper class for printing to the console.","og:url":"https:\/\/mariusbancila.ro\/blog\/2008\/11\/28\/helper-class-for-console-functions\/","article:published_time":"2008-11-28T00:53:56+00:00","article:modified_time":"2013-08-21T09:12:53+00:00","twitter:card":"summary","twitter:title":"Helper Class for Console Functions","twitter:description":"Helper class for printing to the console."},"aioseo_meta_data":{"post_id":"143","title":"Helper Class for Console Functions","description":"Helper class for printing to the console.","keywords":[{"label":"C++","value":"C++"},{"label":"console","value":"console"},{"label":"Windows","value":"Windows"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:16:02","updated":"2025-12-12 07:23:16","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":8,"uagb_excerpt":"Have you tried to print colored text in a console or put the text at a specific position? You know then that STL or CRT does not provide that functionality. Windows API however, contains a set of functions for working with console windows. The list of these functions is available in MSDN. However, to simplify&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/\" class=\"advgb-post-tax-term\">Windows Programming<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">Windows Programming<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/\" class=\"advgb-post-tax-term\">console<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/\" class=\"advgb-post-tax-term\">Windows<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">console<\/span>","<span class=\"advgb-post-tax-term\">Windows<\/span>"]}},"comment_count":"8","relative_dates":{"created":"Posted 18 years ago","modified":"Updated 13 years ago"},"absolute_dates":{"created":"Posted on November 28, 2008","modified":"Updated on August 21, 2013"},"absolute_dates_time":{"created":"Posted on November 28, 2008 2:53 am","modified":"Updated on August 21, 2013 11:12 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-2j","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=143"}],"version-history":[{"count":3,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/143\/revisions"}],"predecessor-version":[{"id":1666,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/143\/revisions\/1666"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}