demo-escape - string."...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// This program demonstrates escape sequences in C++ #include <iostream.h> const double e = 2.7128; // base of the natural logarithm system int main() { // Some meaningless variables to play with. .. double a = 2.3173; double b = 3; double c = -0.71234567; // Let's look at some escape sequences. .. // tab -- '\t' cout << "Four numbers, separated by tabs: " << a << '\t' << b << '\t' << c << '\t' << e << endl; // double quotes -- '\"' // single quotes -- '\'' cout << "I'd like to print out some quotation marks and apostrophes in a
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: string.&amp;quot; &amp;lt;&amp;lt; endl; // This line won't work: // cout &amp;lt;&amp;lt; &amp;quot;He said, &amp;quot;Don't be so quick to type that string.&amp;quot;&amp;quot; &amp;lt;&amp;lt; endl; // . ..but this one will: cout &amp;lt;&amp;lt; &amp;quot;He said, \&amp;quot;Don\'t be so quick to type that string.\&amp;quot;&amp;quot; &amp;lt;&amp;lt; endl; // newline -- '\n' // backslash -- '\\' cout &amp;lt;&amp;lt; &amp;quot;I can use \&amp;quot;endl\&amp;quot; to get a newline\nor I can use \'\\n\' instead.\n&amp;quot;; cout &amp;lt;&amp;lt; &amp;quot;However, I really should pick one way of doing newlines throughout a program.\n&amp;quot;; return 0; }...
View Full Document

This document was uploaded on 02/10/2011.

Ask a homework question - tutors are online