Hi ! everyone I was trying to use cin.get() like we used to use getch() .
By which I mean using getch()/cin.get() to pause screen till a character is entered.
Here is the code
Code:
#include<iostream>
using namespace std;
int main()
{
cout<<"hi";
cin.get();
}
but when I tried it with this code it failed in first try
Code:
#include<iostream>
using namespace std;
int main()
{
char a;
int i;
cout<<"hi";
a=i=cin.get();
cout<<a<<endl<<i;
cin.get();
}
Then I tried by adding one more cin.get() and it worked
Code:
#include<iostream>
using namespace std;
int main()
{
char a;
int i;
cout<<"hi";
a=i=cin.get();
cout<<a<<endl<<i;
cin.get();
cin.get();
}
Then I thought what value is this second last cin.get() is taking so I tried to save its value in another variable.
Code:
#include<iostream>
using namespace std;
int main()
{
char a;
int i,j;
cout<<"hi";
a=i=cin.get();
cout<<a<<endl<<i;
j=cin.get();
cout<<endl<<j;
cin.get();
}
\
And to my wonder it was always 10 which by ASCII convention means line feed. So can anyone guide me why is this last cin.get() is taking value automatically