โ† All CPP Flashcard Decks

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
  1. What happens when you write to a std::ofstream that was opened with std::ios::binary?

    Answer: No newline translation is performed

    Binary mode suppresses platform-specific newline translation (e.g., '\n' is not converted to '\r\n' on Windows).

  2. Which STL container provides constant-time access by index and automatic resizing?

    Answer: std::vector

    std::vector stores elements contiguously and supports O(1) random access via operator[], resizing as needed.

  3. What does std::copy_if() do compared to std::copy()?

    Answer: Only copies elements satisfying a predicate

    std::copy_if applies a predicate and copies only elements for which it returns true.

  4. Which method must you call before reusing a stream object after a failure?

    Answer: clear()

    clear() resets all error state flags (failbit, eofbit, badbit) so the stream can be used again.

  5. What is the invalidation rule for std::vector iterators after push_back()?

    Answer: All iterators are invalidated if reallocation occurs

    If push_back() triggers a reallocation (capacity exceeded), all existing iterators, pointers, and references are invalidated.

  6. Which STL function object compares two values using operator>?

    Answer: std::greater

    std::greater is a function object that returns true when its first argument is greater than the second.

  7. Which method of std::map returns an iterator to an element if found, or end() if not?

    Answer: find()

    find() searches for a key and returns an iterator to it, or end() if the key is absent.