我是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)'
有人可以帮我吗?
答案 0 :(得分:1)
如果您想要的只是将cv :: String转换为System :: String 的方法,那么这可能会对您有所帮助:
cv::string cvStr = "some text";
std::string str = cvStr.operator std::string();
然后在任何地方使用str!
答案 1 :(得分:0)
您似乎想将cv::String
转换为const 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*