Tricky Tricks ›› Programming Tricks ›› C Languages Tricks ›› Getline Can Be Told To Stop Grabbing Input At Any Designated Character

Getline Can Be Told To Stop Grabbing Input At Any Designated Character

C Programming Tricks

Getline can be told to stop grabbing input at any designated character:

 char temp[100];
 std::cin.getline(temp, 100, '|');
 
 If only two arguments are supplied to getline, getline will stop at the 
 end of the line (at the newline character).
 
 If three arguments are supplied to getline, getline will stop at the 
 character designated by the third argument.
 
 The stop character is not copied to the string.
 The stop character is "eaten" (removed from the input stream).
 

Partners