Chapter 4 Margin Notes

General Note: As the chapter headings indicate, getting stuff in and getting stuff out.

Page 98. As the author points out, it's easier to learn how to program C++ using a Console environment. Starting on Page 157, there is a demo of a C++ program that creates a Windows program.

Page 98. I have NEVER heard of a Console program referred to as a 'CUI' program---whatever you do, NEVER use this term in public---you'll embarrass yourself. Graphical User Interface programs (Windows programs), on the other hand, are commonly referred to as GUI programs. Feel free to use this term.

Page 99. The Compiler note at the bottom of the page is significant. I prefer that you use the newer style (no .h) and that you use this statement

using namespace std;

Page 100. We discussed 'cout' quite a bit last week.

Page 100. I'm sure you will hear and see the term 'stream' quite often in this book. As I mentioned last week, it's just a series of characters.

Page 101.  I have never seen anyone be such a stickler--you could also output a single character to the Console with double quotes, like this

cout << "A";

Page 104.  Confused about the "\n" in the cout statement? "\n" is known as an escape sequence and stands for new line character---it's the same as 'endl', except that it can be included as part of the character string in cout. By the way, there are other escape sequences. "\t" generates a tab in a cout statement. There's a list of them on Page 107.

Page 105.  You may have missed this in the author's discussion, but the flush statement can be used to clear everything out of the output buffer and onto the console screen. like this...

cout << flush;

Page 107.  Notice Table 4.1. There's the list of the other Escape Sequences. Notice how you need to use an Escape Sequence to output quotation marks or apostrophes to the console. Like this...

cout << "Budweiser is the \"king\" of beers";

Page 108.  Layout charts can come in quite handy---I've used them for 25 years.

Page 110.  I/O Stream Manipulators are listed in Table 4.2. Please don't spend a lot of time on these. I would much prefer that you use your time learning how to program than to produce beautiful console output.

Page 113.  Feel free to experiment with formatting Floating-Point Output. It may come in handy later--but the essence of this course is learning the art of programming. Don't waste your precious time trying to make your programs 'pretty'.

Page 114.  Borland C++ supports the clrscr() function (it's contained in conio.h) but Microsoft C++ does not appear to. One point added to your final numeric grade if you figure out how to do this in Microsoft Visual C++.

Page 118. Note the author indicates that input is NOT AS EASY as output. Very true!

Page 118. Before you can accept input into your computer, you must decide what you'll accept and into what kind of variable it will go.

Page 119-120. You won't find much better of an explanation of cin that you see on these pages.

Page 120. A little tricky---if you do code this up and enter 

74 92 88

be sure you include a space in there.

Page 121. As the author indicates, asking the user to enter values for more than one variable at a time is a bad idea. And DON'T FORGET to include appropriate prompts for the values you need. For instance, if you want the user to enter their name, use a cout statement to tell them that. Like this...

#include <iostream>
#include <string>

using namespace std;
int main()
    string name;
    int age;

    cout << "What is your name? ";
    cin >> name;
    cout << "How old are you? " ;
    cin >> age;
    cout << name << ", in 100 years you will be " << (age + 100) << " years old!";
    return 0;

String data can be tricky--the author will talk about it later on in the chapter..

Page 124. Read the rules for reading single-character data carefully with cin. 

Page 127. You can use the get() function of the cin object as an alternative input form to read single characters. Most likely, you'll be reading Strings---which is discussed on Page 128.

Page 128. Read this section on reading String input carefully---otherwise, I'm sure you'll be asking about it later.

Page 131. In case you're coding this up, there is a comma between "cin" and "name" on this line of code, not a period


Page 131. This code works fine using the Borland compiler---however, with Visual C++, I find that you need to hit the ENTER key twice to get it to work. You can read about this 'bug' by following this link

Page 134. cin >> ws does the trick!

Pages 136-137. Don't be intimidated by the name 'object'---cin and cout are really objects that you've been using all along. Later on in the course, you'll create objects of your own.

Page 137. With this line of code, ifstream is the object type, fin is a variable name, and the file to be opened is "sample.txt"

ifstream fin("sample.txt");

Page 137. Notice that you can also specify a full path name for your file, by using double backslash escape sequences to separate directory names.

ifstream fin("c:\\mydocuments\\sample.txt");

Page 138. Don't be too concerned about c_str() at the moment--we'll learn more about it in Chapter 9.

Page 139. You don't know anything about an if...then...else statement yet--so don't be terribly concerned about this section.

Page 140. Notice how there's an 'h' following stdlib but not the other libraries. This is essential for the Visual C++ program to compile.

Page 140. the exit() function terminates the program, and returns a value to the Operating System. This value can be used by a program that may have 'called' this program. A return value of anything other than 0 is considered to be an abnormal termination of the program.

Page 143. You don't know anything about loops yet--so don't be terribly concerned about this section.