1-Hello Variables

1-Hello Variables - int number = 0; // Variables work the...

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

View Full Document Right Arrow Icon
// C++ Introduction with Hello World #include <iostream> // Input | Output header file for reading | writing to the console. // notice that there is no .h on the header file. There actually is iostream.h // but that header file has been replaced by the c++ standard header file, these // header files do not use the .h extension and are functionally different from // their counterparts of the same/similar name int main (void) { std::cout << "Hello World" << std::endl; // cout replaces printf and uses redirection // << is the stream insertion operator // cout stands for console output, where the console is // the standard output stream // endl stands for end line, essentially the same thing // as using the escape operator \n, except that it flushes // the buffer to the output stream. Which forces the writing // to the stream // Variables
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int number = 0; // Variables work the same as they did in C // You'll see that the syntax between C and C++ is the same // the difference come in with what we can do in C++, there // are some new keywords, and programming constructs and // variable types std::cout << "Give " << "me " << "an " << "integer: "; std::cin >> number; // cin stands for console input, it works the same as cout // just in the opposite direction, notice that we are using // greater than signs this time. // Just imagine them as arrows pointing in the direction // that the data will be going to std::cout << "Your number is: " << number << "\nTwice that number is: " << number * 2 << std::endl; return 0; } /* Hello World Give me an integer: 5 Your number is: 5 Twice that number is: 10 Press any key to continue . . . */...
View Full Document

This note was uploaded on 10/05/2011 for the course CS 37 taught by Professor Glenncuevas during the Summer '09 term at Irvine Valley College.

Ask a homework question - tutors are online