Doubt doubt doubt

we use ’ \n ’ to get to the new line.
Then why cin.get;ine() taking it as a string ???
It’s not making sense to me.
Please explain this part.

hello @parth_tyagi

string is nothing but an array of characters.
so cin.getline() can read a string having single or more characters .
so it can read \n as well.

refer this thread for clarity ->

can you explain the difference between endl; and ’ \n ’ .

Both endl and \n serve the same purpose in C++ – they insert a new line. However, the key difference between them is that endl causes a flushing of the output buffer every time it is called, whereas \ n does not.

bhaiya…input buffer kya h ??? And flushing of buffer…matlab??? I don’t use ’ \n ’ … to mujhe pata nahi h how it works.

tum keyboard se jo bhi input dete ho wo pehle input buffer me store hota hai aur phir waha se program read karta hai.
same usi tarah hamara program output ko pehle output buffer me store karta hai aur phir wo output screen pe display hota hai.
buffer clear karna matlab jo bhi store hai buffer me use remove karna

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.