diff b/w cin.get and gets
Various input methods
Hello @nasa.saumya15,
-
gets()
Syntax:
char* gets(char* str);
The gets() function reads characters from stdin and stores them in str until a newline character or end of file is found.
where,
str: Pointer to an character array that stores the characters from stdin. -
cin.get()
sytax:
char* cin.gets(char* str, int size, char delimiter);
delimiter: Default value is ā\nā i.e. end of line.
cin.get(str , size) will behave the same way as gets(str).
Now consider the scenario where you want to take multi-line input and want to store it in a single string there also cin.get() gets your work done as in cin.get(str, size, ā$ā) and now the string also takes the newline character and terminates when you enter $ .
Hope, this would help.
Give a like, if you are satisfied.