basic.cpp
//basic.cpp //A first program in c++ //Include standard input/output routines--#include is a preprocessor directive #include <iostream> using namespace std; //This program has one c++ function called main //main returns an integer and requires no arguements e.g. () int main() { //declare and initialize integers int i = 10, j = 5; //use the console output routine from the std I/O namespace -- cout //also use the end line symbol endl from the std namespace //cout is an object // the << operator (normally left shift) is overloaded to mean put to cout << "Welcome to ECE 538" <<endl; cout << "i = " << i << " j = " << j << endl; cout << "sum = " << i+j << " difference = " << i - j << endl; //return an integer when finished return EXIT_SUCCESS; }
Compile wirh: cl -EHsc -W4 basic.cpp
C:\classes\ece538\work>basic Welcome to ECE 538 i = 10 j = 5 sum = 15 difference = 5
Maintained by John Loomis, updated Sun Dec 31 16:54:59 2006