0

I recently found a typo in my project which looked like this:

std: cout << "Hello World!" << std::endl;

It was compiling fine, although I noticed that I had a using std::cout directive in the include chain that was required to prevent a syntax error from cout being out of scope. I wrote a test program to see what was going on, and it turns out that std:; is a perfectly valid line of c++. What is std: doing, and why doesn't it cause syntax errors when combined with the call to cout?

Max
  • 11
  • 1
  • 3
    Looks like a goto label to me. I.e. you could now add `goto std;` to your function and it would jump to that line. – john Nov 16 '20 at 18:35
  • TL;DR of the dupe: This is called a label. It is what goto and switch statements use. – NathanOliver Nov 16 '20 at 18:35
  • Awesome, thank you! For whatever reason, searching for "std:;" doesn't come up with the prior questions. – Max Nov 16 '20 at 19:06

0 Answers0