c++ - Why is the letter 'D' missing in the output? -


#include <iostream> using namespace std;  int main() {      char ch1 = 'a';     char ch2 = 'b';     char ch3 = '\n';     cout << ch1 << '\t' << ch2 << ch3;     cout << 'c' << '\t' << 'd' << '\b' << ch1 << ch3;     //return 0;     system("pause"); } 

output is:

a        b c        

why last letter , not d?

everything cout gets outputted. it's terminal interpret '\b' "go 1 character". try redirecting output file , examine (hex)editor see characters (including '\b') there.

at first glance, 1 might think terminals print output as-is. that's incorrect, though. terminals change way behave whenever encounter 1 of special terminal control sequences or characters. '\b' (=0x08=backspace) character 1 of those. more can found @ http://ascii-table.com/ansi-escape-sequences.php . can try printing of terminal , see change colors, rewrite current lines , on , forth. in fact, can use these special sequences , characters make complete gui-like apps in command-line.

note however, not programs can rely on "redirect file" trick see terminal control sequences write stdout. many programs detect whether they're writing terminal or not , adjust usage (or lack thereof) of terminal control sequences accordingly.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -