C++ Escape Sequence Codes
◀ cin.peek() and cin.putback()▶ Alias For a Data Type Amazon
n escape sequence code in C++ is a letter followed by an escape character, a backward slash in this case. Each escape sequence code has its own meaning and does something to the output stream. Below you’ll see a list of them.
There are several C++ escape sequence codes, including newline, backspace, horizontal tab, vertical tab, alert, and carriage return. Many programmers are familiar with only some of them. The fact is that some C++ escape sequence codes such as vertical tab, backspace, and alert are not very useful in programming, but you still should know them.
A friend of mine is an experienced programmer and has been programming ever since high school. One day he asked me to help him solve a problem. He wanted user to type something on the screen, and after enter key was hit, he wanted cursor to go back to the beginning so that the user could overwrite what he just typed. To my surprise, he never knew that the cursor could ever go back!
That is why I think you should know these sequence codes. Here is a brief description of how each one works:
- \n forms a new line so that the next character being read or outputted appears in the next line
- \b goes back one space
- \t forms a horizontal tab
- \v forms a vertical tab
- \a beeps
- \r goes back to the beginning of the current line
Some of these may not work depending on your implementations of C++. Simply try them out and you’ll know which ones work and which don’t.
Next let’s look at how to build an alias for a data type!
◀ cin.peek() and cin.putback()▶ Alias For a Data Type