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 8 Question 100 Discussion

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

What happens when you attempt to compile and run the following code?

#include

#include

#include

#include

#include

#include

using namespace std;

class B { int val;

public:

B(int v=0):val(v){}

int getV() const {return val;}

operator int() const { return val; };};

templatestruct Out {

ostream & out;

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

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

int main () {

int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

fstream f("test.out", ios::trunc|ios::out);

list l(t, t+10);

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

f.close();

f.open("test.out");

for( ; f.good() ; ) {

B i;

f>>i;

cout<

}

f.close();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Charlene
2 days ago
The code looks correct, so I'd say the correct answer is E. The program will display the sequence 1 2 3 4 5 6 7 8 9 10. Can't wait to see if I get this one right!
upvoted 0 times
...
Amira
3 days ago
I think the answer is B) file test.out will be truncated.
upvoted 0 times
...