Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple question about \x escape sequence

22 views
Skip to first unread message

Christiano

unread,
Feb 12, 2018, 9:44:01 PM2/12/18
to
See the following statement:
std::cout << "\105ba" << std::endl;

In the ascii table 105 octal means 'E', so the result is: "Eba"

I want to do the same thing using hexadecimal escape sequence

std::cout << "\x45ba" << std::endl;

And the result is:

$ CC a.cpp
a.cpp:7:16: error: hex escape sequence out of range
std::cout << "\x45ba" << std::endl;
^~~~~~
1 error generated.

The book C++ Primer Fifth edition - Stanley Lippman - in the page 39 says:

""""" C++ Primer 5th, page 39 """""""""""""""""""""""""""""""""
"We can also write a generalized escape sequence , which is \x followed
by one or more hexadecimal digits or a \ followed be one, two, or three
octal digits. The value represents the numerical value of the character."
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

My question is:
How can I write the sequence \x45 + b + a ("Eba") without the compiler
understanding 'b' and 'a' as hexadecimal characters ?

In Octal this problem doesn't exist, example:
std::cout << "\10510" << std::endl;
will print "E10", that is, '1'+'0' will not be interpreted as octal
characters.

Reinhardt Behm

unread,
Feb 12, 2018, 9:48:19 PM2/12/18
to
write it as "\x45" "ba" (not tested)

--
Reinhardt

Christiano

unread,
Feb 12, 2018, 9:55:29 PM2/12/18
to
It works.
std::cout << "\x45""ba" << std::endl;
0 new messages