What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2

Post by answerhappygod »

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end<enter>?#include <iostream>#include <string>#include <list>#include <algorithm>using namespace std;template<class T>struct Out {ostream & out;Out(ostream & o): out(o){}void operator() (const T & val ) {out<<val<<" "; } }; int main (){list<int> l;for( ; !cin.bad() ; ){int i;cin>>i;l.push_back(i);}for_each(l.begin(), l.end(), Out<int>(cout));return 0;}Program will output:

A. 1 2 3
B. 1 2 3 end
C. 1
D. compilation error E. program runs forever without output
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This topic has 1 reply

You must be a registered member and logged in to view the replies in this topic.


Register Login
 
Post Reply