What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <typedef T>
class A {
T_v;
public:
A(T v): _v(v){}
T getV() { return _v; }
};
int main()
{
A<int> a(1);
cout << a.getV() <<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <list>
#include <iostream>
using namespace std;
template<class T>
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 2, 3, 4, 5};
list<int> l1(t1, t1 + 5);
l1.remove(2);
print(l1.begin(), l1.end()); cout<<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; }
};
int main() {
char s[]={"qwerty"};
char t1[]={"ert"};
char t2[]={"ERT"};
sort(s, s+6);
cout<<includes(s,s+6, t1,t1+3)<<" "<<includes(s,s+6, t2,t2+3)<<endl;
return 0;
}
Program outputs:
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 <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 () {
ifstream f("test.in");
list<int> l;
for( ; !f.fail() ; ) {
int i;
f>>i;
l.push_back(i);
}
f.close();
for_each(l.begin(), l.end(), Out<int>(cout));
return 0;
}
Programwill output:
What happens when you attempt to compile and run the following code?
# include <vector>
# include <iostream>
# include <algorithm>
# include <functional>
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[]={3,2,4,1,5,6,10,8,7,9};
vector<int> v1(t, t+10);
for_each(v1.begin(), v1.end(), bind2nd(plus<int>(), 1));
for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs: