Connecting Tech Pros Worldwide Forums | Help | Site Map

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

davinci
Guest
 
Posts: n/a
#1: Sep 8 '05

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.

CK
Guest
 
Posts: n/a
#2: Sep 8 '05

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


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

davinci
Guest
 
Posts: n/a
#3: Sep 8 '05

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


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?

davinci
Guest
 
Posts: n/a
#4: Sep 8 '05

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


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.

davinci
Guest
 
Posts: n/a
#5: Sep 8 '05

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


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.

davinci
Guest
 
Posts: n/a
#6: Sep 8 '05

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


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.

Howard
Guest
 
Posts: n/a
#7: Sep 8 '05

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



"davinci" <flashmx5098@163.com> wrote in message
news:1126187693.475687.102060@g43g2000cwa.googlegr oups.com...[color=blue]
>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.
>[/color]

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


Closed Thread