0

I want to enable c++ syntax support for visual studio code, but none of the guides I've found have worked for me. My environment is treating standard syntax keywords like 'cout' and 'endl' as variable names for whatever reason. I installed MinGW-64 through the visual studio code C++ guide and followed the instructions exactly but that did not work. I also installed several C/C++ extensions, including the one by Microsoft, and it's still showing errors for these things. Is there any work around for this?

Here is the code I have. This is my first time with C++ so I hope I'm not missing anything else important.

#include <iostream>

int main(){

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

 }
  • 1
    How exactly things "don't work"? `cout` *is* technically a variable, but `endl` is not. How can you tell they're "treated as variables" and why does it matter? – HolyBlackCat Dec 29 '20 at 20:25
  • I believe it's treating it like a variable because when I type out keywords like 'endl' it gives me the following error message: "identifier "endl" is undefined." This is typically what I get whenever I get an undeclared variable error. – Jakob Germann Dec 29 '20 at 20:28
  • Can you show us your full code? Also, where does it tell you that: when you compile, or by drawing a red squiggle under `endl` as you type? Also, can you provide the error message verbatim? – HolyBlackCat Dec 29 '20 at 20:31
  • Just posted the code I'm working with. This is my first time working with C++ so I hope it's all just me missing something due to inexperience. – Jakob Germann Dec 29 '20 at 20:36
  • Also, the exact error message is this: identifier "endl" is undefined C/C++(20). The error is just a red squiggle under endl and cout. I haven't been able to compile this at all. – Jakob Germann Dec 29 '20 at 20:39
  • Change `cout << "Hello World!" << endl;` to `std::cout << "Hello World!" << std::endl;` both `cout` and `endl` are in the `std` namespace. – drescherjm Dec 29 '20 at 20:40
  • That worked! Thank you! Why would Microsoft not include that in their code example for setting up c++ with visual studio code? Their method was using what I had previously. – Jakob Germann Dec 29 '20 at 20:42
  • In examples, `std::` is often dropped, for brevity (or they even use `using namespace std;`, which is a bad habit). Learn to get used to typing it, it's how you should do it. – Aganju Dec 30 '20 at 08:34

0 Answers0