I'm a newbie to c++ but I have a background in python, but with that
Said, I have run into a bit of a snag with my toying around with c++.
Before I ask my question, I will show you my code first.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main(){
// Generic input
int x;
cin >> x;
cout <<"\n";
cout << x * 42;
// getline after generic input
string y;
getline(cin,y);
cout << y;
return 0;
}
| |
So when I run the code this way, it will perform the
Math operation, however, it will not continue with the
rest of the // getline after generic input code. Why is that?
Also if I wrap that code into a function and try to run it, it gives me the word
trap after the math operation, and again, why?
Thanks ahead for any explanation!!!