The purpose of cin.get()

what is the purpose of using cin.get() in the above code?

hi @jayasmit98, refer this The use of function cin.get()

what is the purpose when we are not using this to input anything , in the code above it has been used in the program but not to input anything.

@jayasmit98, whenever you use cin before getline(cin,s) you have to use cin.get()
this is because Assuming you have pressed enter after taking input n using cin , the newline character was also put on the stream. When you call cin.get() after that, it will grab and discard the newline character, allowing the rest of your code to properly get the input.

thumb rule :-
whenever you are using cin>>something to take input before getline(cin,somestring) always use cin.get() after cin and before getline