Specifying string literals

Strings are made up of one or more characters, and you can use the escaped characters in string literals too:

    cout << "This is \x43\x2b\05\3n";

This rather unreadable string will be printed on the console as This is C++ followed by a newline. The capital C is 43 in hexadecimal and the + symbol is 2b in hexadecimal and 53 in octal. The \n character is a newline. Escaped characters are useful for printing characters that are not in the character set your C++ compiler uses and for some unprintable characters (for example, \t to insert a horizontal tab). The cout object buffers the characters before writing them to the output stream. If you use \n as a newline it is treated like any other character in the buffer. ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.