STL Containers with Custom Objects

Medium Templates & Generic Programming PRO
🔒 Login to Unlock

Problem Statement

Define an `Item` class with an integer `id` and string `name`. Inside `main()`, create a `std::vector` (which is an STL template container). Read an integer N, followed by N sets of (id, name). Push them into the vector, and print ‘Size: [vector_size]’.

Input Format

Line 1: N. Line 2: N pairs of integer ID and string name.

Output Format

Print the vector's size.

Constraints

1 <= N <= 20

Sample Input

2
1 Pen 2 Pencil

Sample Output

Size: 2

Explanation

STL containers like vector are highly optimized class templates built to hold any valid object type.

Starter Code

#include <iostream>
#include <vector>
#include <string>

class Item {
public:
    // Define id, name, and constructor
};

int main() {
    // Setup vector, read N items, push, and print size
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used