What is the advantage of using gets() function in C++ program to input string data?
Explain with an example
Answers
Answered by
1
ANSWER :
The gets() function enables the user to enter some characters followed by the enter key. All the characters entered by the user get stored in a character array. The null character is added to the array to make it a string. The gets() allows the user to enter the space-separated strings.
PROGRAM :
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char str[100];
cout << "Enter a string: ";
gets(str);
cout << "You entered: " << str;
return 0;
}
OUTPUT :
Enter a string: Have a great day!
You entered: Have a great day!
Similar questions