3

我是 C++ 新手,我想使用 MesasgeBox::Show 显示矩阵,但我无法将 String 转换为 System::String 作为参数。这是我的代码

projectionMatrices(Mat P1, Mat P2){
std::ostringstream stream;

for(int cols = 0; cols <= P1.cols; cols++){
    for(int rows = 0; rows <= P1.rows; rows++){
        stream << P1.at<double>(rows, cols) << '\t';
    }
    stream << '\n';}

String str = stream.str();
MessageBox::Show(str, "My Application", MessageBoxButtons::OKCancel,    MessageBoxIcon::Asterisk);}

这是错误:

1>MessageHandle.cpp(42): error C2665: 'System::Windows::Forms::MessageBox::Show' : none of the 21 overloads could convert all the argument types
1>          c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\system.windows.forms.dll: could be     'System::Windows::Forms::DialogResult  System::Windows::Forms::MessageBox::Show(System::String ^,System::String ^,System::Windows::Forms::MessageBoxButtons,System::Windows::Forms::MessageBoxIcon)'
1>          c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\system.windows.forms.dll: or       'System::Windows::Forms::DialogResult System::Windows::Forms::MessageBox::Show(System::Windows::Forms::IWin32Window ^,System::String ^,System::String ^,System::Windows::Forms::MessageBoxButtons)'
1>          while trying to match the argument list '(cv::String, const char [15], System::Windows::Forms::MessageBoxButtons, System::Windows::Forms::MessageBoxIcon)'

有人可以帮我吗?

4

2 回答 2

3

如果您想要的只是将 cv::String 转换为 System::String的一种方法,那么也许这可以帮助您:

cv::string cvStr = "some text";
std::string str = cvStr.operator std::string();

然后在任何你想要的地方使用 str !

于 2013-09-03T13:25:43.980 回答
0

看来您想转换cv::Stringconst char *.

std::string str = String(some_cv_string); // from cv::String to std::String
const char * cstr = str.c_str(); // from std::String to const char*
于 2014-10-22T16:22:28.873 回答