Function for Compile + Build Windows PowerShell

I’ve been looking on google for how to make a custom function in Windows PowerShell so I can simply type run FILENAME and compile and run code, similar to the Mac-Specific section on the module. But I can’t find anything that tells me what I need for Windows. I’ve looked into this article about Profiles, but I’m still lost.

Wondering if someone could help me out with how to write the function and make it work.

You can make a batch file, then put all of your C++ files into the directory with the batch file.

Inside the batch file:

g++ %1.cpp -o %1.exe -Wall -Wextra && %1.exe
pause

To use it, cd into the directory with your terminal and type:

.\YOUR_BAT_FILENAME.bat the_name_of_cppfile

This should compile and run the file for you.

Thanks for the help @GhOsT. Was able to use some of your code to make my own batch file

@echo off

echo [1] - Compiling	.....	%1
g++ -std=c++0x %1.cpp -Wall -O2 -o %1.exe

if %errorlevel% == 0 (
    	echo [2] - Running	.....	%1
	echo:
   	%1.exe
)

echo:

Nice!