Home > Back-end >  Please comment wstring output problem
Please comment wstring output problem

Time:12-03

C + + white great god to their consult
Static int output_fa_and_child (struct tree * fa)
{
Printf (" process PID: % d \ t process name: % ws \ n ", the fa - & gt; Elem. ProcessID, fa - & gt; Elem. ProcessName. C_str ());
Struct tree * vy=fa - & gt; FirstChild;
While (vy) {
Output_fa_and_child (vy);//recursive call
Vy=vy - & gt; NextBro;
}
return 0;
}

This string of code, basically can output process, but there are some process can not output process name, even the back of the newline character also doesn't work, would like to ask what is the great god,

CodePudding user response:

Don't process name is normal,
When input and output of the first test, or pointing to an unsigned short t [10]=x0fff {0}; Such random space can produce such a situation,

CodePudding user response:

Is probably the process name contains Chinese, Chinese GBK code in Chinese Windows console is displayed properly, if it is in Chinese wide string (Unicode), is part of a display in Chinese will be a problem, see https://blog.csdn.net/binaryhead/article/details/109993588

CodePudding user response:

Want to see your tree in previous deal with what kind of

CodePudding user response:

 static int output_fa_and_child (struct tree * fa) 
{
Printf (" \ xe8 \ XBF \ x9b \ xe7 \ xa8 \ x8bPID: % d \ \ t xe8 \ XBF \ x9b \ xe7 \ xa8 \ x8b \ xe5 \ x90 \ x8d: % s \ n ", the fa - & gt; Elem. ProcessID, fa - & gt; Elem. ProcessName. C_str ());
Struct tree * vy=fa - & gt; FirstChild;
While (vy) {
Output_fa_and_child (vy);
Vy=vy - & gt; NextBro;
}
return 0;
}

CodePudding user response:

For computer no noise, only the binary bytes; To the human brain is gibberish, GBK: 0 xb0 0 xa1, Unicode - 16 LE: 0 x4a 0 x55, Unicode - 16 BE: 0 x55 0 x4a, utf-8 8-0 x95 xE5 0 0 x8a

CodePudding user response:

reference 5 floor 4 teacher zhao reply:
for computer there is no noise, only binary bytes; To the human brain is gibberish, GBK: 0 xb0 0 xa1, Unicode - 16 LE: 0 x4a 0 x55, Unicode - 16 BE: 0 x55 0 x4a, utf-8 8-0 x95 xE5 0 0 x8a

This is you have been emphasized for computer without noise, is actually to wrangle, we see the human eye computer display character is garbled, a computer the code wrong? In the computer, the character encoding of the values in a coding format, forcibly interpreted as another coding format, will be garbled words, your program above printf (" \ xe8 \ XBF \ x9b \ xe7 \ xa8 \ x8b... And on the machine running? Not garbled?

CodePudding user response:

The code just because you don't know whether you used to output terminals or window support utf8 encoding display Chinese characters,

CodePudding user response:

CHCP 65001
Have a try

CodePudding user response:

Got a breakpoint tried, found to be wstring garbled, when acquiring the process name before not gibberish, endures in the tree structure is gibberish,,
  • Related