On Friday, August 12, 2011 09:02:36 AM Dave Baldwin wrote:
> On 12 Aug 2011, at 14:10, amir a. wrote:
> > 2 - int a,b,c,d;
> > 
> >    while( 1 ) {
> >    
> >       cin >> a >> b >> c >>d ;
> >       if( a < 0 || b < 0 )
> >       
> >          break;
> >       
> >       cout << a << " " << b << " " << c << " " << d << endl;
> >    
> >    }
> 
> while true
> 	a, b, c, d = gets.split.map {|s| s.to_i}
> 	break if a < 0 || b < 0
> 	STDOUT << a << " " << b << " " << c << " " << d << "\n";
> end

A nitpick: This doesn't do exactly the same thing. The 'cin' version, if I 
understand it, will read the next four things which look like integers, 
separated by any whitespace, including newlines. It only seems like it 
operates per-line since that's how you'd manually enter text into stdin, but 
the program actually sees it as an unbroken stream. So you can enter each 
number on its own line, or eight of them on the same line...

The gets version will read a single line. If there aren't enough integers, 
some variables will be nil. If there are too many, some integers will be 
ignored, not carried over to the next line.

Similar things apply to the first example.

Also, both Ruby and C++ have a higher-level construct than "\n" -- why not:

  puts "#{a} #{b} #{c} #{d}"