xemacs,gdb,I can't input from the terminal in main function,but others functions well.

D

davinci

I had study it for a long time .but I didn't solve it .Ihad read
<<Debuging with GDB>>
But I didn't get something useful.
include<iostream>
#include<cstdlib>
using std::isdigit;
int main()
{ int i=4;
try
{
while(1)
{
std::cin>>i;
if(!isdigit(i))
{
std::cout<<"not digit ,once more"<<std::endl;
std::cout<<"i="<<i<<std::endl;
}
if(i==2)
{
std::cout<<"good boy"<<std::endl;
}
else
{
std::cout<<"bad boy"<<std::endl;
}

}
}

catch(...)
{
std::cout<<"execption had happened"<<std::endl;
}
}
//end of the codes
//from here: std::cin>>i;
(gdb) s //here ,no chance to input anything.
(gdb) s
(gdb) s
not digit ,once more
(gdb) s
i=4
(gdb) s
(gdb) s
bad boy
(gdb) s //no chance to input anything,there is no prompt for input.
(gdb) s
(gdb) s
not digit ,once more
(gdb) s
i=4
(gdb)


But I can input something when I am no in the main function.

anyhelp?
thanks very much.
 
C

CK

Not sure If I understand the issue correctly. Even I am not able to
compile your code, it gives me syntax error.

If I change the line using std::isdigit;
to
using namespace std;

then only I can compile the code and run it.

So let me know what is the issue you are having now.

CK
 
D

davinci

Thanks.
It is ok now.
but ,it is so inscrutability.
I had remember that there is no the function isdigit() ,and there is no
'using std::isdigit' I can't input anything in main function.

I didn't know why.
and if I declare using namespace std before main function and then
didn't use
,such as std::cout,
then error is:cout is not have been declared.
why?
 
D

davinci

Now ,I can't again.I can't input anything.
it is so interesting .
Is it a bug of gdb?
But I think input a integer is a common operation.
 
D

davinci

Now ,I can't again.I can't input anything.
it is so interesting .
Is it a bug of gdb?
But I think input a integer is a common operation,so I can't belive it
is the problem of compiler.
 
D

davinci

I am sorry to touble you.
I get the answer now .
if I enter interger all is ok.
once I enter a non-integer characater,then I can't input anymore.
 
H

Howard

davinci said:
I am sorry to touble you.
I get the answer now .
if I enter interger all is ok.
once I enter a non-integer characater,then I can't input anymore.

One way to avoid that problem is to input into a char (or char array, or
std::string). Then you can check if the character is in the range '0'
through '9', (and only then convert it to an integer if that's what you
need).

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top