Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About std:cout in C++

Tags:

c++

std

gcc

Is there an error in this code:

#include <iostream>
using namespace std;

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

GCC detects no error but std:cout does not seem standard.

like image 768
Minimus Heximus Avatar asked Dec 02 '22 16:12

Minimus Heximus


1 Answers

There's no error. I could rewrite your code to make it clearer:

#include <iostream>
using namespace std;

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

You created a label named std. cout is used unqualified, which is okay since you have the using-directive for std above it. And you can concatenate string literals by writing them next to each other as you did. This is perfectly well-formed code that prints "hello" followed by a newline.

like image 74
Barry Avatar answered Dec 17 '22 16:12

Barry