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 file stream method returns the current position of the get pointer?
Answer: tellg()
tellg() returns a std::streampos representing the current get (read) pointer position.
What is the primary difference between std::set and std::multiset?
Answer: std::multiset allows duplicate keys
std::multiset allows multiple elements with equal keys, whereas std::set enforces uniqueness.
Which C++ function reads a full line of text including spaces from an input stream?
Answer: std::getline()
std::getline() reads characters until a delimiter (default '\n') and stores them in a std::string.
What does std::accumulate() compute by default?
Answer: The sum of all elements starting from an initial value
std::accumulate folds a range using operator+ by default, starting from a provided initial value.
Which error bit is set when a stream operation fails due to logical error, such as reading an int from non-numeric input?
Answer: failbit
failbit is set when a logical I/O operation fails, such as a type mismatch during formatted input.
What does std::priority_queue guarantee about the top() element?
Answer: It is the largest element by default (max-heap)
By default, std::priority_queue uses std::less, making top() return the greatest element.
Which STL algorithm finds the minimum and maximum elements of a range simultaneously?
Answer: std::minmax_element()
std::minmax_element returns a pair of iterators pointing to the minimum and maximum elements.