Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 2 Question 102 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 102
Topic #: 2
[All CPP Questions]

What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?

#include

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) {out<

int main () {

ifstream f("test.in");

list l;

for( ; f.good() ; ) {

int i;

f>>i;

l.push_back(i);

}

f.close();

for_each(l.begin(), l.end(), Out(cout));

return 0;

}

Program will output:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Tiera
8 days ago
I'm not sure, but I think the program will output B) 1 2 3 3 because the last integer will be printed twice.
upvoted 0 times
...
Devorah
12 days ago
I agree with Valentine. The program will output A) 1 2 3 because the for_each function will print the integers in the list.
upvoted 0 times
...
Valentine
13 days ago
I think the program will output A) 1 2 3 because it reads the integers from the file and pushes them into the list.
upvoted 0 times
...

Save Cancel