Page 1 of 1

getline after cin>>

Posted: Fri Jun 23, 2006 9:39 pm
by nukeu666
what exactly am i supposed to pass to cin.ignore if i need to use cin.getline after using a cin>> previously?
one methos i read about uses limits...does OJ support including limits?

Posted: Sat Jun 24, 2006 11:54 am
by chunyi81
Hmmm... I have not used cin.ignore before. May I suggest an alternative? How about using two getlines? You can also use getline this way:

getline(cin,str);

where str is a C++ string.

One to read in the newline after the cin >> and the second one to read in the line you want.

Posted: Mon Jun 11, 2007 2:48 am
by ghst08
you can use cin.get(source, len) to get the string and then use
cin.ignore(INT_MAX, '/n')

that way itll clear out the buffer left up to the amount of INT_MAX or till it finds a null terminator.

Re: getline after cin>>

Posted: Wed Oct 29, 2014 6:29 pm
by Zyaad Jaunnoo
nukeu666 wrote:what exactly am i supposed to pass to cin.ignore if i need to use cin.getline after using a cin>> previously?
one methos i read about uses limits...does OJ support including limits?

Code: Select all

Use cin.get() to swallow the carriage return.
Then use cin.getline(..)