-5

I've encountered an error with the hello world program in c++ vscode, it doesn't print out Hello World also warns me the i don't have gcc

#include <iostream.h>
using namespace stl;

integer main()
{
output << "Hello World"
return 0;
}
JaMiT
  • 14,422
  • 4
  • 15
  • 31
  • 1
    How are you compiling/running? – Rehmaan Momin Jul 16 '21 at 06:05
  • 2
    There are a number of issues (at least 5) here that suggest the source you are learning from is bad. We do have a list of [suggested books](https://stackoverflow.com/q/388242/1171191). – BoBTFish Jul 16 '21 at 06:06
  • vscode sits in top of a compiler that has to be downloaded and installed separately. Assuming there's no GCC because you're on a Windows OS, I recommend msys2. [Here are installation instructions](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2) – user4581301 Jul 16 '21 at 06:09
  • @BoBTFish That might be a bit harsh towards the learning source. Most of the issues are typos and oversights that are easy for a beginner to make in their first program, even if learning from a good source. The other issue might be influence from a C background, again no fault of the instruction. I would expect the beginner to catch these mistakes when the program is compiled, but there is no compiler in this case. I think blaming the instruction is premature at this point. – JaMiT Jul 16 '21 at 06:28
  • Please provide the exact error message (as text). It is reasonable to guess that future visitors with the same issue will search for that error message, and you want them to find your question and its resolution, right? – JaMiT Jul 16 '21 at 06:32
  • I would not be concerned about all the downvotes. They are probably from people who took one look at your code without bothering to read your question. If you want to give those people less to complain about, you could make your program even simpler, trimming it down to three lines. First line: `int main()` Second line: `{` Third line: `}` This program has no functionality, but it is enough to demonstrate that you don't have gcc installed. – JaMiT Jul 16 '21 at 15:00

2 Answers2

3

The source code won't compile, here is a working hello world program:

#include <iostream>


int main()
{
   std::cout << "Hello World\n";

   return 0;
}

In addition to this, please make sure you have a compiler.

  • 3
    Please reconsider recommending things that are often considered bad practices: [`using namespace std;`](http://stackoverflow.com/q/1452721/1171191) and [`endl`](https://accu.org/index.php/journals/2619) ([another for `endl`](https://www.youtube.com/watch?v=6WeEMlmrfOI)). – BoBTFish Jul 16 '21 at 06:09
  • 1
    @BoBTFish I know its bad practice generally, but for a small hello world program to just test that you can run c++ code, it should be fine. Thanks for pointing it out though. – Rehmaan Momin Jul 16 '21 at 06:11
  • 2
    Don't want to get into all the reasons in the comments, but why teach bad practices now, then try to unteach them later? – BoBTFish Jul 16 '21 at 06:12
  • 1
    @BoBTFish Fair point. I have changed the code to reflect this. – Rehmaan Momin Jul 16 '21 at 06:14
  • 1
    Ya gotta hook 'em while they're young. – user4581301 Jul 16 '21 at 06:25
0

Looks like u don't have a compiler to compile the code, consider installing gcc or any other c++ compiler first. Your source code also seems to have some syntax errors, try this hello world program:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!\n";
    return 0;
}
yashsh
  • 81
  • 11