Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Getting Started

 

Concepts

 

Variables

 

Some Important Terminology

 

Comments Identifier Precedence
Assignment Operator: = int Data Type Preprocessor Directive
Block of Code: {  } Integer Division Statement Terminator
Case Sensitivity Literal Stream Insertion Operator: <<
Data Type Logic Error Stream Extraction Operator: >>
Equality Operator: == main Function Variable
Escape Character: \ Memory White Space
Function Modulus Operator: %  

 

Examples and Projects

 

 

cout << and cin >>

 

Along with endl, they are contained in the header file iostream.h.

They are accessed through the pre-processor directive #include <iostream.h>.

A newer version, #include <iostream> utilizes namespaces (covered later).

If the latter is used you must add some additional code.

 

Approach 1

 

#include "stdafx.h"  /Microsoft precompiled header file

#include<iostream>   //necessary when writing to screen or reading from keyboard

int main()

{

      //ising cout and endl operators in namespace std;

      std::cout<<"An example using scope resolution operator"<<std::endl;

}

 

Approach 2

 

#include "stdafx.h"

#include <iostream>

using std::cout;

using std::cin;

using std::endl;

int main()

{

            int aNumber = 0; 

            cout<<"Enter a number"<<endl;

            cin>>aNumber; 

            cout<<"You entered: "<<aNumber<<endl; 

    return 0;

}

 

 

Approach 3 - Approach We Will Use

 

#include "stdafx.h"

#include <iostream>

using namespace std;

int main()

{

      int aNumber = 0; 

      cout<<"Enter a number"<<endl;

      cin>>aNumber; 

      cout<<"You entered: "<<aNumber<<endl; 

    return 0;

}