What is the use of cin.get()?
Funtion of cin.get()
@jha.aparna17,
When using cin, you type in characters (keys on your keyboard) that appear in the command prompt. That’s what your program - specifically, cin reads. Normally, it will automatically take as many characters as it needs to input. For instance, if you say
cin >> myIntVar;
and you type 37643, it gets all 5 characters, treats them as an integer, and correctly puts 37643 into myIntVar.
By using cin.get(), you get only one of those characters, and it is treated as a char.
Sometimes, the command prompt will close as soon as the program finishes, meaning you can’t see the output. Putting cin.get() forces the program to wait for the user to enter a key before it can close, and you can see the output of your program.
Its not important if are using an ide but u may want to use if u are using terminal
u can refer this discussion The use of function cin.get()
In case of any doubt feel free to ask
If u got the answer then mark your doubt as resolved
thank you, that was helpful!!!