如何在messagebox上显示全局变量?

时间:2013-05-13 02:54:11

标签: c++-cli messagebox

这是代码,

void horizontal_calculate()
{
    String ^aa = filenames[0];
    std::string file1(marshal_as<std::string>(aa));
    String ^bb = filenames[1];
    std::string file2(marshal_as<std::string>(bb));

    double Result3=horizontal_read(file1);
    double Result4=horizontal_read(file2);
    double result=Result3/Result4;
    result1=result;
    System::Diagnostics::Debug::WriteLine("{0}",result);
}

private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {


             for (int i = 0; i < filenames->Length; i++)
                 System::Diagnostics::Debug::WriteLine(filenames[i]);

             semicircle();
             horizontal_calculate();
             oblique();


             MessageBox::Show("Time Ratio = "result1"","Screening Result",MessageBoxButtons::OK, MessageBoxIcon::Information);
         } 

我已将double = result1声明为全局变量。

在标识符'result1''之前出现错误“错误C2146:语法错误:缺少')',所以我该如何解决这个问题?

是否需要以及如何将double转换为字符串?

谢谢大家。

1 个答案:

答案 0 :(得分:1)

如果问题出在MessageBox行中,请按以下方式编写:

MessageBox::Show(
    String::Format("Time Ratio = {0}", result1),
    "Screening Result",
    MessageBoxButtons::OK, MessageBoxIcon::Information);