⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽

Writing to the Console

Computer Programming C++ / Getting Started

Now that you have a console window open and can write text to it, you're ready for some additional challenges. In this section we will see how certain characters present problems, when written in code. The following videos will demonstrate how we handle these situations.

Okay, so I've decided to save you a few seconds. Here's the list:
\' - single quote
\" - double quote
\\ - backslash
\n - new line
\r - carriage return
\t - tab
\0 - null character

If you ever look at C++ code online, it won't take you long to discover that there are a couple different ways to create a line break. This video will cover both.

Please note: there are two versions of the code to the left! Click the second "Main.cpp" to see the alternate version.

The Standard Namespace

Throughout the semester, you will see "std" in our code. This refers to the "standard" namespace. We'll cover namespaces in more detail, in future chapters.

Using a namespace is a way to allow programmers to name functions, variables, etc. without worrying about having their name conflict with code that other programmers write.

Review Questions

The following are examples of questions similar to what you can expect to see on the next exam.

Hover over a question to show the answer.
  1. What is #include <iostream> used for? It lets us read and write text to the console.
  2. How do you use an escape character? By using a backslash. Ex: \t is a tab character.
  3. What does the code: using namespace std; do? Allows us to use functions inside of the standard namespace, without having to prefix them with std::.
⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽
© Ryan Appel