I've started learning C++ recently, and I was experimenting with cout and cin with the code below:
#include <iostream>
using namespace std;
int main()
{
int x = 0;
string y;
cin >> x >> y;
cout << "x: " << x << '\n';
cout << "y: " << y << '\n';
}
I was taught that the input would have to be seperated with whitespaces for something like this to work. But, when I input into the console something like 420foo, cin works perfectly to seperate and assign 420 as x and foo as y, giving the output:
x: 420
y: foo
This seems pretty convenient, but I'm not sure how this works, or if this is unintended... I've tried looking through some sources online, but to no avail. Any help would be appreciated for uncovering this mystery!