0

hi friends im facing one problem
i have used cin to input a choice like (cin>>ch)
then i have used to take input to string as getline(cin, string_s)
but getline does not works when i use cin

if i donot use cin it works well
why it is happening???
and is there any alternative to take integer then string input

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Kanoisa
0

Hi,
I think the issue you are facing is that the input stream needs cleared after a call to cin before getline. As far as i recall cin leaves the '\n' character on the stream so getline returns with nothing. See this post from narue on how to achieve this http://www.daniweb.com/software-development/cpp/threads/90228 Im not 100% sure this is the correct explanation but i do recall seeing and having this problem before and that was the solution.

Hope this solves your problem

Edited by Kanoisa: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.