{"id":1505,"date":"2022-08-30T15:17:05","date_gmt":"2022-08-30T15:17:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/25\/problem-about-wchar-t-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:05","modified_gmt":"2022-08-30T15:17:05","slug":"problem-about-wchar-t-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-wchar-t-collection-of-common-programming-errors\/","title":{"rendered":"problem about wchar-t-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c4e1477113874fc2971bee45c984b3d6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAlcott<br \/>\nc encoding wchar-t<br \/>\nI&#8217;m trying to print out a wchar_t* string. Code goes below:#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;wchar.h&gt;char *ascii_ = &#8220;????&#8221;; \/\/line-1 wchar_t *wchar_ = L&#8221;????&#8221;; \/\/line-2int main() {printf(&#8220;ascii_: %s\\n&#8221;, ascii_); \/\/line-3wprintf(L&#8221;wchar_: %s\\n&#8221;, wchar_); \/\/line-4return 0; }\/\/Output ascii_: ????Question:Apparently I should not assign CJK characters to char* pointer in line-1, but I just did it, and the output of line-3 is correct, So why? How could printf() in<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bf2efd892ae4853e708580df90ba6659?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nZac<br \/>\nc++ deprecated wchar-t<br \/>\nHello I have a pump class that requires using a member variable that is a pointer to a wchar_t array containing the port address ie: &#8220;com9&#8221;.The problem is that when I initialise this variable in the constructor my compiler flags up a depreciated conversion warning.pump::pump(){this-&gt;portNumber = L&#8221;com9&#8243;;}This works fine but the warning every time I compile is anoying and makes me feel like I&#8217;m doing something wrong.I tried creating an array and then setting the member variable like this:pump:<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dcdfcff66a48390d0b903a47fbc0e9c2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndavy<br \/>\nc linux console wchar-t wchar<br \/>\n1 It&#8217;s really strange that wprintf show &#8216;?&#8217; as 3A9 (UTF16), but wctomb convert wchar to CEA9 (UTF8), my locale is default en_US.utf8. As man-pages said, they should comform to my locale, but wpritnf use UTF16, why?excerpt from http:\/\/www.fileformat.info\/info\/unicode\/char\/3a9\/index.htm? in UTFUTF-8 (hex) 0xCE 0xA9 (cea9)UTF-16 (hex) 0x03A9 (03a9)2 wprintf and printf just cannot be run in the same program, I have to choose to use either wprintf or printf, why?See my program:#include &lt;stdio.h<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/95a4ccd3f88ebe9c44e169bfffd9bd55?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAjay<br \/>\nc++ wchar-t<br \/>\nI&#8217;m new to c++.I know wchar_t is wide character.What is wrong in the following code ?? Did i not include the appropriate library ??#include&lt;iostream.h&gt; #include&lt;conio.h&gt; void main() { wchar_t *s=L&#8221;Hello, World&#8221;; cout&lt;&lt;s; getch(); }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/138a0977ee407dfe0bfebc55a3cc1275?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNick Prowse<br \/>\nvisual-c++ visual-studio-2012 wchar-t c2664 lpcwstr<br \/>\nI&#8217;m new to c++. Coding in VS Express 2012 with Update 1. OS is Win 7 Ultimate SP1 x86.For the code below, which is the contents of main.cpp (I&#8217;ve put under Source Files), I get the following errors:Error 2 error C2664: &#8216;RegSaveKeyW&#8217; : cannot convert parameter 2 from &#8216;wchar_t&#8217; to &#8216;LPCWSTR&#8217; \\registrybackup_test\\registrybackup_test\\main.cpp 17 1 RegistryBackup_testError 1 error C2440: &#8216;initializing&#8217; : cannot convert from &#8216;const wchar_t [40]&#8217; to &#8216;wchar_t&#8217; \\registrybackup_test\\registrybac<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-25 11:02:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Alcott c encoding wchar-t I&#8217;m trying to print out a wchar_t* string. Code goes below:#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;wchar.h&gt;char *ascii_ = &#8220;????&#8221;; \/\/line-1 wchar_t *wchar_ = L&#8221;????&#8221;; \/\/line-2int main() {printf(&#8220;ascii_: %s\\n&#8221;, ascii_); \/\/line-3wprintf(L&#8221;wchar_: %s\\n&#8221;, wchar_); \/\/line-4return 0; }\/\/Output ascii_: ????Question:Apparently I should not assign CJK characters to char* pointer in line-1, but I just [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1505","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1505"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1505\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}