1

In this code snippet:

char name[25];
int a;
cout<<"Enter number: ";
cin>>a;
cout<<"Enter name: ";
gets(name);

before I can even give the string name[] any value, it automatically skips it. But when I alter the code and put the string input before the integer input,

char name[25];
int a;
cout<<"Enter name: ";
gets(name); 
cout<<"Enter number: ";
cin>>a;

it works perfectly. Why is the behavior of the gets() function so? Any other string stream funtions that I can use as alternative to it?

Satyam Raj
  • 41
  • 9

0 Answers0