Basic input and output operations

First Program in CPP

When learning C++, the first program you write is generally a turning point because it summarizes input, processing, and output. The goal of this pilot program is straightforward: ask the user for a number, then repeat it back. Let us break down this classic C++ program, examining its various parts and features.



Program:

#include<iostream.h>

using namespace std;

int main() {

int a;

cout<<"enter a number"; //input statement

cin>>a;

cout<<"the number is : "<<a; //output statement

return 0;

}


Output Statement (cout)


  • The cout is a predefined object that represents the standard output stream


Syntax: cout << string or variable;

The operator << is called the insertion or put-to operator.

Example:


cout<< “C++ is better than c”;


Causes the string in quotation marks to be displayed on the screen.


Input Statement (cin)


  • The cin is a predefined object that represents the standard input stream


Syntax:
cin >> variable;

The operator >> is called the extraction or get from the operator.

 

Example

cin>>a;

 

The value given through the keyboard will be stored in the variable ‘a’.


In the end, my first attempt at writing C++ code captures the essence of input/output activities by encapsulating user interaction in a clear and organized manner. We build relationships with our users by using cout and cin, which encourages interaction and participation. This is evidence of the power and adaptability of C++ as a programming language.

← Back Next →

Comments

Popular posts from this blog

Wrapper Class

Information Security & Essential Terminology

Information Security Threat Categories