Exercise 2-1 (Hello, world; family)

Chapter_2     Hello Stream     Exercise_2-2







Exercise 2-1     TCP1, p. 119


Exercise 2-1. Modify Hello.cpp so that it prints out your name and age (or shoe size, or your dog’s age, if that makes you feel better). Compile and run the program.




Family.cpp         download


#include <iostream> // Stream declarations
using std::cout; // console output
using std::endl; // newline

int main()
{
cout << "Hello, world! My name is John Doe. I am "
<< 38 << " today!" << endl;
cout << "My dog's name is Wolfy. He is 1 year old.\n";
}
/*
g++ Family.cpp -o Family
./Family
Hello, world! My name is John Doe. I am 38 today!
My dog's name is Wolfy. He is 1 year old.
*/





Note:  See also ch2-HeYou in Section Strings.









Chapter_2     Hello BACK_TO_TOP Stream     Exercise_2-2



Comments

Popular posts from this blog

Contents