When I run the program bellow with this input: 12 .45A 32 I get these really strange results.
x = 12
y = -858993460
ch = ╠
z = -9.25596e+061
Here's the program...
#include <iostream>
using namespace std;
int main() {
int x, y;
char ch;
double z;
cin >> x >> y >> ch >> z;
cout << "x = " << x << endl;
cout << "y = " << y << endl;
cout << "ch = " << ch << endl;
cout << "z = " << z << endl;
return 0;
}
I just starting with C++ and am experimenting. These aren't the results my book seems to think they should be.
Also, I'm running this program from the console. I'm using Visual C++ Express to write the program, but if I use its debug feature it closes the console that it opens right after the program runs - so I can't see the output. I've read about several solutions as to how to keep the console open after the IDE runs the program, but frustratingly none of them worked for me.
EDIT: After some more experimentation, I think I've discovered my confusion. The .45 was causing the thing to fail, and only the first variable was getting set by the input. The weird stuff was just the stuff in those memory spaces...
Well, such an extraction from cin I have never done from keyboard, but from ideone.com, what works for me is all values in one line, separated by spaces.