I was wondering what the diffrence between the two as far as reading info.
cout << "Enter a string: ";
gets(var);
or
cout << "Enter a string: ";
cin.getsline(var, 40);
gets seems shorter, but is there a reason to use one over the other?
Thanks
I was wondering what the diffrence between the two as far as reading info.
cout << "Enter a string: ";
gets(var);
or
cout << "Enter a string: ";
cin.getsline(var, 40);
gets seems shorter, but is there a reason to use one over the other?
Thanks
Last edited by Tenacious_newb; 04-11-2002 at 10:22 AM.
I can think of 2 quick reasons
1. gets does not protect against buffer overflow, getline does
2. you shouldn't mix and match i/o streams, they may not be synchronised. For instance, gets() followed by getline might read the same information.
Thanks a lot, good to know, I am working my way through two diffrent books and one of them used gets() exclusivly, and the other doesnt even mention it!
thanks again