I'm trying to examine a C++ code from my tutorial book. I've written this using CodeBlocks IDE:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
/*...*/
using namespace std;
/*...*/
int main (void){
cout << "Please enter name and age: \n\n:>";
string _sInput = "";
int _intInput = -1;
cin >> _sInput >> _intInput;
cout << "Hello " << _sInput << "!\n";
cout << "You have aged " << _intInput << " years.";
}
Based on what was discussed in the book by Mr. Stroustrup, now that I have given the variable _intInput
an intial value, if I input wrong data like James Boy
I am supposed to receive an output like this:
Hello James!
You have aged -1 years.
But what I get is You have aged 0 years.
just like the time I have not given an intial value.
Is there anything wrong with my code or what?!