troubleshooting weird cin >> problem

This is weird ive never seen anything like it before. I swear its the boogeyman.

1
2
3
4
bool b;
cout << "Testing... " << endl; //makes it here
cin >> b; //crashes here after I input a number
cout << "Testing... " << endl;  //doesn't make it here 


But I've found I can:
1
2
3
char bc;
cin.get(bc);
b = bc - 48;


However if I use that method, I am no longer able to cout << b << endl;
Although I can still printf it.

Please help. What kinds of things could be causing this.

Is it possible to have passed the cin stream to a function and the function grabbed onto it and won't let go of it?


Sorry for not being able to use precise technical terms, but thats the best I can think of.
I cannot reproduce your problem, but it is not in reading a bool. ¿what else do you have?
¿what else do you have?


A migraine, and over a thousand lines of culprit code.
1
2
3
4
5
6
7
8
9
10
11
bool getencryptionmethod()
{
    if (cin.fail()) {cin.clear(); clearcin(cin);}
    english << "Encrypting or decrypting a message? \n";
    english << "0. for Encryption.  1.  for Decryption.\n" ;
    bool rv;
    carrotjews:cout<<'>';
    cin >> rv;
    if (cin.fail()) {clearcin(cin); cin.clear(); }
    return rv;
}


It crashes at line 8. However if I comment out line 8 and replace it with rv = 0; it runs smoothly.
I was in the process of removing char pointers from my code as a whole and replacing them with strings. If that helps any. However I doubt it will because I had already replaced many lines of code and its impossible to say which, if any, if thats even the cause, had any effect.

Thanks again for your help.
If the read fails, the variable remains in an undefined state. However I don't think that that is causing the crash.

I was in the process of removing char pointers from my code as a whole and replacing them with strings
Run it through a debugger and perform a backtrace, you may be dereferencing an invalid pointer
I don't know. I just read through pretty much my entire program and I've eliminated practically any pointer that causing a dereference of an invalid pointer.
Topic archived. No new replies allowed.