#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
cout开发者_JAVA技巧<<"enter ur no. plz";
cin>>i;
cout<<"ur no. is:"<<i;
cin.get();
return 0;
}
This code is not displaying the integer I entered. It returns back after entering an integer and hitting enter. I am using dev C++.
After the user enters the integer, there is still a newline character left in the input buffer. cin.get() reads that character, then the program immediately ends. You could put an additional call to get if you want the program to stay open. Or, before the call to get, you could have a call to ignore:
std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
That would clear the newline character from the buffer.
Or you could run your program from the command line, you'll see the output then.
Add some endl
s:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
cout<<"enter ur no. plz"<<endl;
cin>>i;
cout<<"ur no. is:"<<i<<endl;
cin.get();
return 0;
}
精彩评论