Why C++ standard reserves the formfeed character? - c++

from the following question I begin to know the meaning of \f in c++:
Escape sequence \f - form feed - what exactly is it?
but why c++ have this formfeed character? is there any c++ program that runs on a typewriter?

The formfeed character is not only for typewriters, it's universally recognized by all printers (or printer drivers) to stop the current page and advance to the next.

There is a number of characters that can be expressed with notation like \t, \b, etc. There is nothing magic in this list. This is just a simple way to insert characters with values less than space (0x20) into the string. The list of these characters has primarily historical base. These chars are used in old programs. Why should they stop compiling? The negative impact from this feature is minimal to none.
The language itself does not put any meaning into these chars. They are simply placed into a string or char constant. The program deals with them.

Related

What does regex [*\f]+ mean?

In the org-mode the outline-regexp variable is set to "[*\f]+".
I am not able to figure out what it stands for, referred this without success.
Edit:- [*\f]+ changed to "[*\f]+"
The default value matches asterisks and page breaks:
"[*\f]+"
http://www.emacswiki.org/emacs/OutlineMode#toc2
\f stands for form feed, which is a special character used to instruct the printer to start a new page.
[*\f]+ Then means any sequence entirely composed of * and form feed, arbitrarily long.
C-hig (elisp) Regexp Special RET
Note also that the usual regexp special characters are not special
inside a character alternative. A completely different set of
characters is special inside character alternatives: `]', `-' and `^'.
So [*\f]+ matches any sequence which is at least one character long, and contains (only) any number and combination of asterisks, backslashes, and the letter 'f'.
EDIT:
Ah, you actually meant "[*\f]", did you? That's not the same thing as the regexp [*\f] (as the latter would be represented in string read syntax as "[*\\f]").
Make sure you quote appropriately.
If you did mean "[*\f]" then the \f is indeed a form-feed, as indicated by the other answers.

What to use to represent a lambda character in C++

In the program, Lambda λ theoretically represents nothing: ''. I thought of representing this programatically as '\0', but obviously that terminates a string which is not necessarily what lambda does. Also, I am reading in from istringstream and it has problems reading that character in.
So what character would you use?
I'm assuming you have a reason for representing Int,Char,Int as a string, rather than just define a struct to hold the data.
As you say, \0 doesn't work as it terminates the string. But there are other invisible ASCII characters that you can use and easily escape in C++. Have a look at this list of escape codes.

Regular Expression in c++ for control character -space

Regular Expression in c++
Is there a way to check all control characters without space(tab,newline, carraige return)?
I tried couple of stuff with no success
[:cntrl:] considers all the control character including space(\n\r\t))
I would like to consider all control except space?
Are this valid way of going about doing this?
[:cntrl:]-[:space:]
I don't think there are any regex implementations which allow you to construct subsets of the POSIX character classes. But any string matching ^([^[:cntrl:]]|[[:space:]])*$ will fulfill your criteria. That is, each character has to be a non-control character, or a space character.
(Dunno what flavor C++ supports; I believe you should not have to backslash-escape anything, but haven't checked.)

C++ - Escaping or disabling backslash on string

I am writing a C++ program to solve a common problem of message decoding. Part of the problem requires me to get a bunch of random characters, including '\', and map them to a key, one by one.
My program works fine in most cases, except that when I read characters such as '\' from a string, I obviously get a completely different character representation (e.g. '\0' yields a null character, or '\' simply escapes itself when it needs to be treated as a character).
Since I am not supposed to have any control on what character keys are included, I have been desperately trying to find a way to treat special control characters such as the backslash as the character itself.
My questions are basically these:
Is there a way to turn all special characters off within the scope of my program?
Is there a way to override current digraphs definitions of special characters and define them as something else (like digraphs using very rare keys)?
Is there some obscure method on the String class that I missed which can force the actual character on the string to be read instead of the pre-defined constant?
I have been trying to look for a solution for hours now but all possible fixes I've found are for other languages.
Any help is greatly appreciate.
If you read in a string like "\0" from stdin or a file, it will be treated as two separate characters: '\\' and '0'. There is no additional processing that you have to do.
Escaping characters is only used for string/character literals. That is to say, when you want to hard-code something into your source code.

What's the Magic Behind Escape(\) Character

How does the C/C++ compiler manipulate the escape character ["\"] in source code? How is compiler grammar written for processing that character? What does the compiler do after encountering that character?
Most compilers are divided into parts: the compiler front-end is called a lexical analyzer or a scanner. This part of the compiler reads the actual characters and creates tokens. It has a state machine which decides, upon seeing an escape character, whether it is genuine (for example when it appears inside a string) or it modifies the next character. The token is output accordingly as the escape character or some other token (such as a tab or a newline) to the next part of the compiler (the parser). The state machine can group several characters into a token.
An interesting note on this subject is On Trusting Trust [PDF link].
The paper describes one way a compiler could handle this problem exactly, shows how the c-written-in-c compiler does not have an explicit translation of the codes into ASCII values; and how to bootstrap a new escape code into the compiler so that the understanding of the ASCII value for the new code is also implicit.
It generally escapes the following character:
In a string literal or character literal, it means escape the next character. \a means 'alert' (flashing the terminal, beeping or whatever), \n means 'linefeed', \xNUM means an hexadecimal number for example.
If it appears as the last visible character before a newline, whether within a string or not (and even within a line-wide comment!), it acts as a line-continuation: The following newline character is ignored, and the next line is merged with the current line.
escape character with a following character (like \n) is a single character for C compiler - scanner presents it to parser as character token, so there is no need in special syntax rules in parser for escape character.