Skip to content
Related Articles

Related Articles

cin get() in C++ with Examples
  • Difficulty Level : Basic
  • Last Updated : 17 Jan, 2020

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Input:

Geeks for Geeks

Output:



Geeks for Geeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Input:

GFG

Output:

GF

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :