String char array

cin.get we are using because of whitespaces right and also cin.get(); and cin.getline();what’s the Diff between them and why cin.get() used before the loop started

please reply me fast

sorry i missed your doubt

  1. cin
    It is used to read a word or character.
    It terminates on encountering whitespace or endline charater (’\n’)
  2. cin.get(char_array,number_of_characters,delimiter)
    To read characters including special characters like ’ ', ‘\n’ and ‘\t’.
  3. cin.getline(char_array,max_Size,delimiter)
    It is used to read a sentence or a paragraph.
    It terminates on encountering endline character.
    It also reads the whitespace.

Difference?

  1. The get() function is much like getline() but rather than read and discard the newline character, get() leaves that character in the input queue.
  2. get() leaves the delimiter in the queue thus letting you able to consider it as part of the next input.

Explanation:
cin.getline() reads input up to ‘\n’ and stops

cin.get() reads input up to ‘\n’ and keeps ‘\n’ in the stream

For example :

char str1[100];
char str2[100];
cin.getline(str1 , 100);
cin.get(str2 , 100);
cout << str1 << " "<<str2;

input :
1 2
3 4
output 1 2 3 4 // the output expexted

When reverse them
For example :

char str1[100];
char str2[100];
cin.get(str2 , 100);
cin.getline(str1 , 100);
cout << str1 << " "<<str2;

input :
1 2
3 4
output 1 2 // the output unexpexted because cin.getline() read the ‘\n’

here first cin.get() take “1 2” but left ‘\n’ in the stream
which is taken by cin.getline()

Usage:
If you are talking about the newline character from a console input, it makes perfect sense to discard it, but if we consider input from a file, you can use as “delimiter” the beginning of the next field.

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved

so cin.getline can also read the below it means below row every row and cin.get reads only the first one and then just give the space and execute the program

so in char array if we got this type we basically use cin.getline always for the next char to input or read otherwise if we used only cin,get the first row of the char will be input and read and then only execute

and here in the program why before cin.getline we first used cin.get why so tell me that also

please reply me fast

wait you have many doubt in this

plz watch this first cin.get() V/s cin.getline()

after this all your doubt will be resolved

if you have further doubts feel free to ask

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.