English

Standard I/O Strems in C++

Advertisements
  • Introduction to Standard I/O in C++
  • Preprocessor directive
  • Structure of C++ Program  
Maharashtra State Board: Class 11

Introduction to Standard I/O in C++

In C++, While performing Input/Output operations i.e., read data from standard input device (keyboard) and write data to standard output device (screen), Must include iostream header file in C++ program 
iostream is the standard header file which contains a set of small and specific general purpose functions for handling the data 
The standard input and output operations in C++ are performed by using I/O stream such as cin for input and cout for output 

  • cin :
    The cin is used to read a number, a character, or a string of characters from a standard input device, normally the keyboard. The extraction operator (>>) is used along with cin
    Syntax : cin >> variable 1 >> -- variable n
    Example: cin >> a >> b;
  • cout : 
    The cout is used to display an object onto the standard device, normally the video screen. The insertion operator (<<) is used along with cout. 
    Syntax : cout << variable 1 << -- variable n;
    Example : cout << x << y;
Maharashtra State Board: Class 11

Preprocessor Directive

C++ provides a #define directive to define symbolic names. The #define is a directive to the C++ preprocessor. The #define directive causes a symbolic name to become defined as a macro. A macro is associated with a body. The general form of simple macro definition is 

Syntax : #define   macro_name   body of macro 
For example: #define    PI    3.1459265

C++ preprocessor conceptually processes the source text of C++ program before compiler parses the source program it replaces every occurrence of a macro name in the program text with a copy of the body 

Other examples of simple macros are : 
#define   STEP_SIZE   10
#define   EOF                -1
#define   MAXINT       214783647

Maharashtra State Board: Class 11

Structure of C++ Program

The C++ program contains six sections as follows :

  • Include files 
  • Class declaration 
  • Class functions definitions 
  • Non-member function prototypes
  • Main function program
  • Non member function definitions 

These sections may be placed in a separate code file and then compiled independently or jointly. Header files (with the .h extension) are included at the beginning using #include. 
Class declarations and definitions appear before the main() function, and non-member function prototypes are declared before main() and defined after main().

Sample C++ Program

#include <iostream>
using namespace std;

int main()
{
    cout << "C++ is better than C";
    return 0;
}

Output : C++ is better than C

Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×