getline C++

Ritiksangam
1 min readAug 13, 2021

--

C++ program to read string using cin.getline()

C++ program to read string using cin.getline()

C++ getline() is a standard library feature for reading a string or a line from an input source. A getline() function gets characters from the input stream and adds them to the given string object until it determines that the character is delimiting. If any, the value stored in string object str shall be replaced with the current string when doing so.

Parameters:

Delim: This is the delimitation character that tells the function to stop reading further input after the character is reached.

Str: It is a string object, and the input is stored within this object after reading from the stream.

Is: It is an istream class object, and tells the stream function from where to read the input.

Return Value: This function will return a certain input stream as the parameter which is accepted.

Name, address, about a person and print in different lines will be read in this program, the name will contain spaces and dots, the address will contain space, commas, and other special characters, as well as mixed characters, will be included in this program. Using the cin.getline() function, we can read all data, and print using cout.

--

--