Last Updated on December 6, 2021 by Admin 2
What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?
#include <iostream>
#include <fstream>
#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 (){
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f(“test.out”);
list<int> l(t, t+10);
for_each(l.begin(), l.end(), Out<int>(f));
f.close();
return 0;
}
- file test.out will be created and opened for writing
- file test.out will be created and opened for reading
- no file will be created nor opened
- file test.out will contain sequence 1 2 3 4 5 6 7 8 9 10
- compilation error