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:
stdis the namespace.::is the scope operator, which looks inside the namespace.coutis 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,cinandendl, from<iostream>. - Strings:
string, from<string>. - Containers:
vector,mapandset, from<vector>,<map>and<set>. - Algorithms:
sortandfind, 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
stdis short for standard.- It is the namespace for the C++ standard library.
- The
::operator looks a name up insidestd. - Keep your own names out of
std.