Examveda

What will be the output of the following C++ code?
#include <list>
#include <string>
#include <iostream>
using namespace std ;
typedef list<string> LISTSTR; 
int main()
{
    LISTSTR :: iterator i;
    LISTSTR test;
    test.insert(test.end(), "one");
    test.insert(test.end(), "two");
    LISTSTR test2(test);
    LISTSTR test3(3, "three");
    LISTSTR test4(++test3.begin(),
    test3.end());
    cout << "test:";
    for (i =  test.begin(); i != test.end(); ++i)
        cout << " " << *i << endl;
    cout << "test:";
    for (i =  test2.begin(); i != test2.end(); ++i)
        cout << " " << *i << endl;
    cout << "test:";
    for (i =  test3.begin(); i != test3.end(); ++i)
        cout << " " << *i << endl;
    cout << "test:";
    for (i =  test4.begin(); i != test4.end(); ++i)
        cout << " " << *i << endl;
}

A. test

B. test one

C. test two

D. test: one
two
test: one
two
test: three
three
three
test: three
three

Answer: Option D


Join The Discussion

Related Questions on Standard Template Library (STL) in C plus plus