First MinGW C++ program on Windows

MinGW is a port of GCC to Windows, many people use Visual Studio C++ IDE on Windows, but it's not freeware and it's huge and complex, sometimes a lightweight development environment is the thing you want. Download a MinGW distribution and unpack it to local, you can find a distribution here: https://nuwen.net/mingw.html.

Go to the unpacked folder and double click the open_distro_window.bat and type g++ --version, you are good to go.

 
 
E:\sync\MinGW>g++ --version
g++ (GCC) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 

Here is an example C++ program, it's very simple

 
#include  <iostream>
#include <list>
using namespace std;
 
int main(int argc, char **argv)
{
    list<int> il={1,2,3,4,5,6};
 
    for(auto i:il)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
 
 

To compile the file execute g++ test.cpp, the executable file will be a.exe, execute it in command line, the output will be

 
G:\tmp>a
1 2 3 4 5 6