using namespace std

What Does std Mean in C++?

std is short for standard. It is the namespace that holds the C++ standard library, including cout, string and vector. Here is what that means.

On this page
  1. The short answer
  2. Reading std::cout piece by piece
  3. What lives in std
  4. Why the prefix matters
  5. Things to avoid
  6. Quick summary

The short answer

std is short for standard. It is the namespace that holds the C++ standard library, which includes names such as cout, cin, string, vector and sort.

If you searched for what is std :: in cpp, the answer is the same. The prefix tells the compiler to look in the standard library’s namespace for the name that follows it.

Reading std::cout piece by piece

Take std::cout apart:

  • std is the namespace.
  • :: is the scope operator, which looks inside the namespace.
  • cout is the name inside the namespace. It is the standard output stream.
#include <iostream>

int main() {
    std::cout << "Hello, world\n";
}

What lives in std

The standard library holds many names that beginners use early. Each name is declared by a header, which you include at the top of the file:

  • Input and output: cout, cin and endl, from <iostream>.
  • Strings: string, from <string>.
  • Containers: vector, map and set, from <vector>, <map> and <set>.
  • Algorithms: sort and find, from <algorithm>.

If a name seems to be missing, check that you included the header that declares it.

Why the prefix matters

The prefix tells a reader exactly where a name comes from. That helps when your own project has a name that could clash with a library name, or when you read code that uses several libraries at once.

Things to avoid

The standard generally does not allow a program to add its own declarations to std. A few exceptions exist, such as specializing certain standard templates for your own types. Keep your own names in your own namespace.

Quick summary

  • std is short for standard.
  • It is the namespace for the C++ standard library.
  • The :: operator looks a name up inside std.
  • Keep your own names out of std.

The complete guide to using namespace std

Using Namespace std in C++ Explained
Read the guide

Keep exploring

Guides from other topics

All topics →

Unary Operators in C++

Learn what unary operators in C++ are, from the one-operand symbols like !, ~, ++ and * to prefix vs postfix, precedence and common mistakes, with examples.