Various input methods

diff b/w cin.get and gets

Hello @nasa.saumya15,

  1. 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.

  2. 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.