cin get() in C++ with Examples
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; } |
chevron_right
filter_none
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; } |
chevron_right
filter_none
Input:
GFG
Output:
GF
Recommended Posts:
- Pi(π) in C++ with Examples
- feclearexcept in C++ with Examples
- set_symmetric_difference in C++ with Examples
- ratio_not_equal() in C++ with examples
- Map of Vectors in C++ STL with Examples
- C/C++ if else if ladder with Examples
- C/C++ while loop with Examples
- C/C++ do while loop with Examples
- C/C++ if statement with Examples
- C/C++ if else statement with Examples
- ratio_equal() in C++ with examples
- C/C++ For loop with Examples
- wmemset() in C/C++ with Examples
- std::mismatch() with examples in C++
- std::to_address in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

