In the future, C # Calls C ++ProgramFirst, experiment.
Prepare the C ++ program first:
# Include < Stdio. h >
# Include < Iostream >
Int Main ()
{
Printf ( " Hi " );
Int V1, V2;
STD: CIN > V1;
V2 = V1 * 2 ;
STD: cout < V2 < STD: Endl;
}
Use C # To call:
Meteorology
Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
UsingSystem. diagnostics;
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
BIND ();
}
Private Void BIND ()
{
PROCESS p = New Process ();
P. startinfo. filename = @" F: \ code \ CPP \ firstcmd \ debug \ firstcmd.exe " ;
// P. startinfo. Arguments = "";
P. startinfo. useshellexecute = False ;
P. startinfo. redirectstandardinput = True ;
P. startinfo. redirectstandardoutput = True ;
P. startinfo. createnowindow = False ;
P. Start ();
//
P. standardinput. writeline ( " 2 " );
String Output = P. standardoutput. readtoend ();
Response. Write (output );
// If (P. hasexited)
// P. Kill ();
}
}