-2

I have a MAC OS Mojave machine and gcc does not work on it. When i run the following code it does nothing and goes to new terminal line

 #import <iostream>;
  using namespace std;
  int main() {
     cout << "Hello World!!";
     return 0;
  }

PLS HELP!! I even tried using code from w3Schools

Blastfurnace
  • 18,411
  • 56
  • 55
  • 70
UrTech Tips
  • 59
  • 1
  • 6

1 Answers1

2

Two things:

  1. Your code had some errors. #import is deprecated, use #include instead. You don't need a semicolon after #include statements. Also, you need to use << to give "Hello World!!" to cout, not >>. If you don't use using namespace std;, you need to specify the namespace for cout. In this case, it would be std::cout.

Here's your corrected code:

#include <iostream>

int main() {
   std::cout << "Hello World!!";
   return 0;
}
  1. gcc (or g++, since you're working with C++) doesn't run code after you compile it. If you're just running something like g++ main.cpp, g++ will generate a file called a.out. This is your compiled binary. To run it in the terminal, type ./a.out in your terminal and press enter.
UnicornsOnLSD
  • 631
  • 6
  • 24