getline-and-write-function-in-C++ .

In this session i have discuss getline and write function in C++ .


The getline() function is used to get a line of text . It is line oriented input function .

The write() function is used to display a line of text . It is also line oriented function .


Example : Write a program that demonstrate the getline function .

    #include<iostream>
    using namespace std;
    int main()
    {  
          int size=30;
          char name[size];
          cout<<"Enter the name : ";
          cin.getline(name,size);
          cout<<name;
          return 0;
    }
    
    OUTPUT : Enter the name : Shashank Tripathi 
             Shashank Tripathi
           

Example : Write a program that demonstrate the write function .

    #include<iostream>
    #include<cstring>
    using namespace std;
    int main()
    {  
          char*name="Shashank Tripathi";
          int l=strlen(name);
          cout.write(name,l);
          return 0;
    }
    
    OUTPUT : Shashank Tripathi
           

Welcome to AndroidATPoint.

back image                     next image