get-and-put-function-in-C++ .

In this session i have discuss get and put function in C++ .


The istream and ostream provide the two function get() and put() . The get() take the single character from user including blank space. It is in two version get(char*) and get(void) . The put() is used to display the data on screen .


Example : Write a program that demonstrate the get function .

    #include<iostream>
    using namespace std;
    int main()
    {  
          char ch;
          cout<<"Enter the character : \n";
          cin.get(ch);
          cout.put(ch);
          
                    return 0;
    }
    
    OUTPUT : Enter the character :
             h
             h
           

Example : Write a program that demonstrate the get function .

    #include<iostream>
    using namespace std;
    int main()
    {  
          char ch;
          cout<<"Enter the characters : \n";
          cin.get(ch);
          while(ch!='\n')
          {
                cout.put(ch);
                cin.get(ch);
          }
          
                    return 0;
    }
    
    OUTPUT : Enter the characters :
             Ram is a good boy
             Ram is a good boy
           

Welcome to AndroidATPoint.

back image                     next image