1.

Explain getline() function with a suitable example.

Answer»

getline() function is used to read the whole line of text that ends with a newline character.

Here getline() function is invoked for reading character input into the variable line. When we type \n, the reading is terminated or size-1 characters are read. The newline is accepted but converted to null character.

# include <iostream>

int main()

{

char city [50];

cout<< “City Name :“;

cin.getline(city, 50);

cout<< “City Name : “<< city << end1;

return 0;

}



Discussion

No Comment Found