2015-07-20 58 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文件中时,它显示在文本框中。如何在文本框中显示返回值?

回答

相关问题