Home
81.
What feature in STL is used to connect algorithms to containers?

Iterators form the bridge between algorithms and containers so that the former (which are generic) can work on the latter without having to know (be customized for) every container type possible.

82.
Would you choose to use container hash_set in an application that needs to be ported to different platforms and built using different C++ compilers?

hash_set is not a C++ standard-compliant container. So, you should not use it in any application that has portability listed as one of its requirements. Use std::map instead.

83.
I need to reverse a string using std::reverse(). What header has to be included for me to be able to use this function?

<algorithm> is the header that needs to be included for std::reverse() to be available.

84.
What role does std::transform() play in converting a string to lowercase using the tolower () function?

std::transform() invokes tolower () for the characters in the string object that are within the bounds supplied to the transform function.

85.
Why do std::wstring and std::string feature exactly the same behavior and member functions?

They do so because they are both template specializations of the template class std::basic_string.

86.
Does the vector change the order of the elements stored in it?

The vector is a sequential container, and elements are stored and accessed in the very order that they are inserted.

87.
What function is used to insert items in a vector, and where is the object inserted?

The member function push_back() inserts elements at the end of the vector.

88.
What function gets the number of elements stored in a vector?

The member function size() returns the number of elements stored in a vector. Incidentally, this is true for all STL containers.

89.
Does the insertion or removal of elements at the end of the vector take more time if the vector contains more elements??

No. Insertion and removal of elements at the end of a vector are constant-time activities.

90.
What is the advantage of using the reserve() member function?

reserve() allocates space in the internal buffer of the vector, and insertion of elements does not need the vector to reallocate the buffer and copy existing contents. Depending on the nature of the objects stored in the vector, reserving space in a vector can result in performance improvements.