CS253: Software Development with C++

Spring 2022

Using Namespace Std

Show Lecture.UsingNamespaceStd as a slide show.

CS253 Using Namespace Std

made at imgflip.com

Namespaces

#include <iostream>

using namespace std;

int main() {
    cout << 1/8.1;
    return 0;
}
0.123457

Namespaces

#include <iostream>

int main() {
    cout << 1/8.1;  // 🦡
    return 0;
}
c.cc:4: error: ‘cout’ was not declared in this scope; did you mean 
   ‘std::cout’?

Namespaces

#include <iostream>

int main() {
    std::cout << 1/8.1;
    return 0;
}
0.123457

How it works

#include <iostream>

constexpr auto pi = 3.14159;
void cout() {
    std::cout << "π=" << ::pi << std::endl;
}

int main() {
    ::cout();
}
π=3.14159