Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream multiple variables on one line?

Tags:

c++

shortcut

cin

int  num1, num2, num3, num4;

This is the only way I've figured out how to do this:

cin >> num1; cin >> num2; cin >> num3;

Is there a way to do something like this?

cin >> num1, num2, num3;

This would be helpful for me to complete assignments and save lines of code without looking sloppy.

like image 573
Big Swoll2001 Avatar asked Aug 31 '26 11:08

Big Swoll2001


1 Answers

>> returns a reference to the same istream, so you can chain them:

cin >> num1 >> num2 >> num3;
like image 184
Aplet123 Avatar answered Sep 03 '26 02:09

Aplet123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!