Labs ICT
๐ŸŽ“ SIWES/IT Login

Namespaces

1 min read | C++ Tutorial
๐ŸŽ“

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

C++ Namespaces

Namespaces prevent name collisions in large projects. The std namespace contains the entire standard library. You can create your own namespaces with the namespace keyword and access members with the :: scope resolution operator. Use using namespace sparingly to avoid ambiguity.

#include <iostream>

namespace Math {
    int add(int a, int b) { return a + b; }
    int multiply(int a, int b) { return a * b; }
}

int main() {
    std::cout << Math::add(5, 3) << "\n";
    std::cout << Math::multiply(4, 7);
    return 0;
}

๐Ÿงช Quick Quiz

Which namespace contains most of the C++ standard library?