File Handling & Standard Template Library (STL) Flashcards
7 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 File Handling & Standard Template Library (STL) flashcards as text
Which STL container provides O(1) average-case insertion, deletion, and lookup?
Answer: std::unordered_map
std::unordered_map uses a hash table internally, giving O(1) average-case for these operations.
What does std::ifstream::seekg() do?
Answer: Sets the get pointer position
seekg() repositions the get (read) pointer within an input stream.
Which STL algorithm removes duplicate consecutive elements from a range?
Answer: std::unique
std::unique collapses consecutive duplicates to single elements and returns an iterator to the new end.
What is the return type of std::vector::emplace_back() in C++17?
Answer: reference
In C++17, emplace_back() was changed to return a reference to the inserted element.
Which file open mode flag creates a new file and truncates it if it already exists?
Answer: std::ios::trunc
std::ios::trunc discards any existing content when the file is opened.
What does std::deque offer compared to std::vector?
Answer: O(1) push_front and push_back
std::deque supports efficient O(1) insertion and deletion at both the front and back.
Which function template in reorders elements so those satisfying a predicate come first?
Answer: std::partition
std::partition reorders a range so elements satisfying the predicate precede those that don't.