Introduction To C++
Introduction To C++
CS 160
Phone: 277-1401
email: [email protected]
url: www.cs.unm.edu/~ingber/
S ource S yntax
file errors
int main()
{
declarations and executable statements
return 0;
}//end block of main
int main() //must have one and only one function named main
{
int number1, number2; //declare two integer variables
cout << “enter two integers” << endl; //prompt for input
cin >> number1 >> number2; //input values for two variables from keyboard
cout << number1 + number2; //output sum of two numbers to the screen
return 0;
}//end block of main
INTEC CS160 - Jeanine Ingber
First Program
•Comments have two forms in C++
•//Single line comments
•/*Multi-line comments*/
•#include files
•<filename.h> //Standard C library header file
•<filename> //Standard C++ library files
•“myfile.h” //Your files (need full path)
•using namespace std;
INTEC CS160 - Jeanine Ingber
Simple I/O
cin
• is an istream object
•streams input from standard input
•uses the >> (input operator)
cout
•is an ostream object
•streams output to standard output
•uses the << (output) operator