cin.getline VS gets

Which one is more preferable cin.getline or gets?

1 Like

gets() is to input a character array whereas cin.getline() is to input objects of standard string class. So, if you are working on a character array, use gets(). And if you are using string object, use cin.getline().

So, here choice is between string and character array, and not between these two functions. Standard string class object provides you several other functions, which may make working on strings easier. you can read about it here.

2 Likes