2015-07-20 56 views
0

我已經在cpp中創建了一個.exe文件,它返回一個整數。我必須在asp.net的文本框中顯示這個返回值。 我cpp的代碼是在這裏使用asp.net運行一個可執行文件並顯示其返回值

#include <iostream> 
using namespace std; 

int addition (int a, int b) 
{ 
    int r; 
    r=a+b; 
    return r; 
} 

int main() 
{ 
    int z; 
    z = addition (5,3); 
    //cout << "The result is " << z; 
    return z; 
} 

而對於上述CPP執行的C#代碼,

protected void Button1_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     var path =Server.MapPath("~/cpp/sample1.exe"); 
     ProcessStartInfo info = new ProcessStartInfo(path); 
     info.RedirectStandardOutput = true; 
     info.UseShellExecute = false; 
     p.Start(); // Send whatever was returned through the output to the client. 
     TextBox1.Text = p.StandardOutput.ReadToEnd(); 
    } 
} 

當執行它,文本框沒有顯示的返回值。但是當我把cout << "The result is " << z;放在cpp文件中時,它顯示在文本框中。如何在文本框中顯示返回值?

回答

相關問題