Open In App

cin get() in C++ with Examples

Last Updated : 17 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

cin.get() is used for accessing character array. It includes white space characters. Generally, cin with an extraction operator (>>) terminates when whitespace is found. However, cin.get() reads a string with the whitespace.

Syntax:

cin.get(string_name, size);

Example 1:




// C++ program to demonstrate cin.get()
  
#include <iostream>
using namespace std;
  
int main()
{
    char name[25];
    cin.get(name, 25);
    cout << name;
  
    return 0;
}


Input:

Geeks for Geeks

Output:

Geeks for Geeks

Example 2:




// C++ program to demonstrate cin.get()
  
#include <iostream>
using namespace std;
  
int main()
{
    char name[100];
    cin.get(name, 3);
    cout << name;
  
    return 0;
}


Input:

GFG

Output:

GF

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads