Run g++ on mac

I wrote a simple code as follows and saved it as 1.cpp

1
2
3
4
5
6
7
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello, world!"<<endl;
return 0;
}


Then I input g++ 1.cpp in my mac terminal, then nothing happens. However if I changed the code above a little (for example, get rid of a ;), then it complains.

Does anyone know how to let it show "Hello, world!"?

Many thanks ahead!
Last edited on
Odds are, if nothing was displayed after running the command, it just worked. Look for a file in that directory called 'a.out,' this is your compiled output file; run it by typing './a.out'

To name the output file, you would type
g++ sourcefile.cpp -o outputfile
Thanks very much!
Topic archived. No new replies allowed.