///C# function to compile C++ code
public string ExecuteCode(string codeText, sting outputFileName) //pass entire C++ code as parameter and the output location
{
string result = ""; //final result that is displayed
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("Cpp"); //creating a C++ compiler
CompilerParameters parms = new CompilerParameters();
parms.GenerateExecutable = true;
parms.OutputAssembly = outputFileName; //set output filename. must include check that path exists
CompilerResults res = codeProvider.CompileAssemblyFromSource(parms, codeText);
if (res.Errors.Count > 0)
foreach (CompilerError err in res.Errors)
result += "Line No.: " + err.Line + " Error No.: " + err.ErrorNumber + " - " + err.ErrorText + "\n";
else
result = "Executable sucessfully created with file name : " + outputFileName;
return result;
}