-5

So, I created a new project, here is my code:

#include <iostream>
using namespace std;
int main() 
{

   return 0;
}

For whatever reason, #include has an error, and the lightbulb won't give me any solutions. I have the code runner and c++ extensions installed.

I'm getting errors left and right for no reason including: A red line under #include

Running the code doesn't work and says "'g++' is not recognized as an internal or external command,operable program or batch file. " which doesn't even exist.

And so much more.

  • 2
    have you followed instruction [Vscode for c++](https://code.visualstudio.com/docs/languages/cpp) ? – Deumaudit Nov 14 '21 at 07:30
  • `using std` line is missing a semicolon. BTW, it should be `using namespace std;` instead. – kiner_shah Nov 14 '21 at 07:31
  • @kiner_shah Even without that it doesnt work. – VoidPhoenix96 Nov 14 '21 at 07:34
  • @Deumaudit Yeah I did – VoidPhoenix96 Nov 14 '21 at 07:37
  • What do you mean it doesn't work? What exactly happens? – kiner_shah Nov 14 '21 at 07:38
  • I mean the inlcude is still underlined and I'm still getting 16 errors everytime I run it lmao – VoidPhoenix96 Nov 14 '21 at 07:39
  • @VoidPhoenix96, please update the post with the relevant details of the errors you get, along with the updated code. – kiner_shah Nov 14 '21 at 07:40
  • You should have had to edit three json files. It may be helpful to add these files to the question because what you describe sounds a lot like a configuration error. That or you forgot to install a compiler. vscode doesn't come with one. – user4581301 Nov 14 '21 at 07:45
  • open new console and type there ```g++```. If it will says ```g++.exe: fatal error: no input files``` then just restart your computer, but if it says ```g++ is not recognized as command``` than you failed to install c++ compiler. Try to reinstall it – Deumaudit Nov 14 '21 at 07:47
  • ***"'g++' is not recognized as an internal or external command,operable program or batch file*** Means you either did not install mingw or its not setup properly. – drescherjm Nov 14 '21 at 12:53

1 Answers1

0

It depends on how you start off learning C++. At the very least your starter sandbox code should look like this:

#include <iostream>
int main()
{
    return 0;
}

and you should have no problems.

When it comes to introducing input/output operators, the use of using namespace std; is a polarizing one.

Method 1:

#include <iostream>
using namespace std;
int main()
{
    return 0;
}

Some people don't want you using it at all because ... what if you decide to create something called "namespace" yourself? In fact, this school of thought is very fearful of global things for reasons that escape me. Then you would have to take it out and rely on the traditional method ...

Method 2: eschewing namespace and using std::. You would have to use std::cout for printing text output to the prompt and std::cin for prompting input from the user.

Also, it looks like you are encountering multiple problems, so try attacking them one at a time. I haven't worked with g++ in a long time, so it sounds like you should first do some research on how to compile and run code with g++.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    While `using namespace std;` is indeed bad practice, the OP's program should build and run without any problems. This sounds like a configuration error, rather than a problem with the code itself. – justANewb stands with Ukraine Nov 14 '21 at 07:47