Basic input-output in C plus plus

Basic input-output in C plus plus
Basic input-output in C plus plus

Basic input-output in C Plus Plus

    Basic Input-Output C plus: C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It makes the performance fast. If bytes flow from main memory to a device like a printer, display screen, network connection, etc, this is called an output operation. 

    If bytes flow from a device like a printer, display screen, network connections, etc to main memory, this is called an input operation.


    InputStream: Input Stream the direction of flow of the bytes is from the device like the Keyboard to the main memory in this process is called input stream.


    OutputStream: Output Stream the direction of flow of bytes is opposite, from main memory to device display screen then this process is called output stream.


    C++ Input/Output Library Header Files

    C++ common used header files are:

    Header Files

    Function and Description

    <iostream>

    It is used to define the cout, in, and color objects, which correspond to the standard output stream, standard input stream,   and standard error stream, respectively.

    <iomanip>

    It is used to declare services useful for performing formatted I/O, such as setprecision and setw.

    <fstream>

    It is used to declare services for user-controlled file processing.


    Standard output stream in C++

    Standard output stream (cout): The cout is a predefined object of the ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with the stream insertion operator (<<) to display the output on a console.


    Example of standard output stream (cout):

    #include <iostream> 

    using namespace std; 

    int main( ) { 

       char ary[] = "Welcome to C++ Codeswithbaby"; 

       cout << "Value of ary is: " << ary << endl; 

    *****OUTPUT*****

    Value of ary is: Welcome to C++ Codeswithbaby


    Standard input stream in C++

    Standard input stream (cin): The cin is a predefined object of the istream class. It is connected to the standard input device, which is usually a keyboard. The cin is used in conjunction with the stream extraction operator (>>) to read the input from a console.


    Example of the standard input stream (cin):

    #include <iostream> 

    using namespace std; 

    int main( )

      int age; 

       cout << "Enter your age: "; 

       cin >> age; 

       cout << "Your age is: " << age << endl; 


    *****OUTPUT*****

    Enter your age: 22

    Your age is: 22 

     

    Standard end line in C++

    Standard end line (endl): The endl is a predefined object of the ostream class. It is used to insert a new line of characters and flushes the stream.


    Example of standard end line (endl):

    #include <iostream> 

    using namespace std; 

    int main( ) { 

    cout << "Welcome To";    

    cout << " Codeswithbaby"<<endl;  

    cout << "End of line"<<endl;  

    }  

    *****OUTPUT*****

    Welcome To Codeswithbaby

    End of line 


    Read Also Post Others Programming Language

    Introduction to C Programming Language
    Introduction to C++ Programming Language
    Introduction to Python Programming Language
    Introduction to Java Programming Language

    Console Input/Output Function In C Programming Language
    Data Conversion Type Casting Implicit and Explicit in C Language


    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.