c++ - Input buffer not clearing -


i encoutering problem cin object of c++. use microsoft visual studio 2013 ultimate edition ide.

#include<iostream> #include<stdio.h> using namespace std; int main() {     char inp[20], inp2;     cout<<"input\t";     cin>>inp;     cout<<"input char";     inp2=getchar();     cout<<inp<<endl<<inp2; } 

the problem after reading input first cin line getchar reading new liine charector. i.e cin leaves new line charecter in buffer after done taking input. getchar reads nw line charector doesnt take input user @ all.

after first input processed, can use cin.ignore() ignore rest of line.

cin>>inp;  // ignore rest of line. cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  cout<<"input char"; inp2=getchar(); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -