Search This Blog

Thursday, 27 December 2012

Difference between cin.getline and cin in C++

You should know the difference between
char string[ 10 ];
  cin >> string;
And
cin.getline(string,10,'\n');

In cin>>string, user keeps on entering characters unless either Enter key or Spacebar is pressed or 10 characters are entered and stored. Where as in Case of cin.getline User may press Enter key, Spacebar or whatever except the Delimeter character (in this case '\n' which is Enter Key). Size of array should also be kept in mind that compiler won't allow you to store more than size of array (10 characters in this case).

No comments:

Post a Comment