[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Problem with cin



hi friend !

what i am writing is not a solution but discussion on y'r problem 

yesterday i worked with your problem and  found some things 
like 
     ones we give irrelevant value to cin  ( wrong data type )
     its value goes to (nil) and 
     it does not let execute any cin coming 
     after thin cin insted of  cin.clear() 
     making it back to 0xffffff...

what could be the reason ? 

enlighten me ...
 


shubh
REC-Surat
--------------------------
                  @>
in love with    /( )\  linux
                 ^ ^ 
--------------------------

On Mon, 22 Jan 2001, Ramkumar Iyer wrote:

> Hi ,
>       Have a look at the code.
>  If  I give some invalid value for one integer (like
> characters) , no values are read into both . Ideally , if
> reading int1 fails then it should print some message and try
> reading int2.Am I missing something?
> 
> #include <iostream.h>
> main()
> {
>   int int1=0;
>   int int2=0;
>   cout << " Enter the int1 val : " << flush;
>   cin >> int1;
>   if(!cin)
>   {
>    cout  << endl << "Error reading int1" << endl << flush;
>    cin.clear();
>   }
> 
>   cout << " Enter the int2 val : " << flush;
>   cin >> int2;
> 
>   if(!cin)
>   {
>     cout  << endl << "Error reading int2" << endl << flush;
>     cin.clear();
>   }
> 
>   cout << endl << " " << int1 << " " << int2 << flush;
> }
> 
> 
> 
> ---------------------------------------------
> LIP is all for free speech.  But it was created
> for a purpose.  Violations of the rules of
> this list will result in stern action.
>