Short answer
What the line does
Everything in the C++ standard library lives in a namespace called std. A namespace is a named group of names, which keeps different libraries from fighting over the same word. To use cout you normally write std::cout, where std:: says where to find it.
The line using namespace std; is called a using-directive. cppreference defines its effect on name lookup: for unqualified lookup of any name after the directive, until the end of the scope it appears in, every name from the namespace is visible as if it were declared in the nearest enclosing namespace that contains both the directive and the namespace. In plain words, after the line you can drop the prefix.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!\n";
}
The same program with no directive:
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
Why people warn against it
cppreference states the risk: using namespace std; at namespace scope introduces every name from std into the global namespace, which may lead to undesirable name collisions, and using-directives are generally considered bad practice at file scope of a header file.
learncpp.com is blunter. Showing a program that starts with the line, it says that if you see this in a textbook or tutorial, the material is probably out of date. Its summary is that in modern C++, using-directives generally offer little benefit, saving some typing, compared to the risk.
A collision
learncpp.com gives an example. If you write your own function named cout in the global namespace and also use using namespace std;, a call to cout becomes ambiguous between your function and std::cout. The compiler fails with an ambiguous symbol error. The same happens when two namespaces each define a name such as x.
The standard library has a very large number of names, so the chance of a clash grows with every name you import. learncpp.com says the possibility of naming collisions increases significantly.
What to write instead
learncpp.com's advice is to prefer explicit namespace qualifiers over using-statements. Write std::cout and std::string. It also says that scoped using-declarations such as using std::cout; are acceptable in .cpp files after the includes, and that using-statements should never go in header files.
A using-declaration brings in one name, not the whole namespace:
#include <iostream>
using std::cout;
int main()
{
cout << "Hello, world!\n";
}
cppreference also shows that a directive can be limited to a block:
{
using namespace std;
vector<int> v3; // Same as std::vector
}
That limits the damage, because the names are visible only inside the braces.
Is it wrong for a beginner
The line is legal C++, and many beginner tutorials still use it. Nothing in the sources says it is an error. The advice is about habit: learning with std:: from day one means you always know where a name comes from, and you will not be surprised when you read other people's code. If your course or tutorial uses it, you can follow along, then switch to std:: prefixes in your own projects.
For what the rest of a first program means, see what does int main mean in C++, and for a plan of what to learn first, how to learn C++ as a beginner.
Teaches C++ to complete beginners as a game where you tap one real line of code at a time.
Get it on Google PlayFree to play. Halls 1 to 4 are free with no time limit, and free players can watch optional rewarded video ads for bonuses. Segfault Pro, a monthly subscription or a 3-month pass paid once, opens hall 5 and up, unlimited practice sets and mock exams, with no ads.
Segfault teaches C++ to complete beginners as a game with 11 halls from variables to loops, functions and arrays. You tap one real line of C++ at a time and watch it run, and each line is compiled and run with a real C++ compiler. It does not teach you to write whole programs by typing, so use it alongside a tutorial such as the ones above.