{"id":3741,"date":"2021-12-11T05:27:03","date_gmt":"2021-12-11T05:27:03","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3741"},"modified":"2022-02-17T08:51:52","modified_gmt":"2022-02-17T08:51:52","slug":"2a-wxwidgets-console","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/11\/2a-wxwidgets-console\/","title":{"rendered":"2a.wxWidgets &#8211; console"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>The two most common ways of displaying anything out on the console is by using <em>wxPuts()<\/em> and <em>wxPrintf()<\/em> . <em>wxPuts()<\/em> prints a string value or variable to the console. <em>wxPrintf() <\/em>formats objects and variables into a string and displays the formatted string much like the regular C++ <em>printf<\/em> function.<\/p>\n\n\n\n<p>When using string constants, we use the <em>wxT()<\/em> function which takes care of the string settings as configured in wxWidgets, in terms of using widechar Unicode characters or the old style narrow ANSI strings. It is safer and the norm these days to handle strings as Unicode to take care of non-English character sets. So using <em>wxT()<\/em> or <em>_T()<\/em> converts a string constant to its Unicode format.<\/p>\n\n\n\n<p>In console apps, we do not use or declare the <em>wxApp()<\/em> object, so it is recommended to call <em>wxInitialize()<\/em> at the start of the program and then call <em>wxUninitialize()<\/em> at the end. They are not compulsory as the code runs even without these functions but it is good practice to put them in your console apps. <\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<p>In the code below, we print out a couple of string values. We also using STL to input some characters from the keyboard and then print them out as wxString.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n#include &lt;wx\/string.h&gt;\n#include &lt;iostream&gt;\n\nint main(int argc, char **argv) {\n\twxInitialize();\n\twxPuts(wxT(&quot;String displayed using wxPuts&quot;));\n\twxPuts(wxT(&quot;Enter a 10 character alphanumeric string without spaces&quot;));\n\tchar str&#x5B;10];\n\tstd::cin &gt;&gt; str;\n\twxPuts(wxT(&quot;\\n\\nText entered was &quot;));\n\twxPuts(str);\n\n\twxUninitialize();\n}\n<\/pre><\/div>\n\n\n<p>This is the output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">String displayed using wxPuts\n Enter a 10 character alphanumeric string without spaces\n teststring\n Text entered was \n teststring<\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW The two most common ways of displaying anything out on the console is by using wxPuts() and wxPrintf() . wxPuts() prints a string value <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/11\/2a-wxwidgets-console\/\" title=\"2a.wxWidgets &#8211; console\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-3741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=3741"}],"version-history":[{"count":5,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3741\/revisions"}],"predecessor-version":[{"id":3762,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3741\/revisions\/3762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=3741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}