About std: cout in C ++

Is there an error in this code:

#include <iostream>
using namespace std;

int main()
{
    std:cout << "hello" "\n";
}

GCC does not detect errors, but std:coutdoes not look standard.

+4
source share
3 answers

There is no mistake. I could rewrite your code to make it clear:

#include <iostream>
using namespace std;

int main()
{
std:
    cout << "hello" "\n";
}

A label with a name has been created std. coutused by unskilled, this is normal since there is a pointer to it above it std. And you can combine string literals by writing them next to each other, just like you. This is a well-formed code that prints "hello" and then a new line.

+12
source

std, cout. , using namespace std;

+4

There is a problem in the code. trying to instruct the compiler to use the std namespace, we are trying to call the cout function, which is defined in the std scope.

thus the correct use of the scope resolution operator

    'std::cout '

but not

    std:cout.

And others noted by writing

    std:

what you do create a label.

+1
source

Source: https://habr.com/ru/post/1607112/


All Articles