2013-06-15 2 views
3

Я новичок в C++ и хочу показать матрицу с помощью MesasgeBox :: Show, но я не могу преобразовать String в System :: String, что мне нужно в качестве параметра. Вот мой кодПреобразование cv :: 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

Вы уверены, что хотите преобразовать cv :: string в System :: String? Потому что, как я знаю, это C# формат для строки, а не стандартная строка (std :: string) в C++. – aisa

ответ

1

если то, что вы хотите, это просто способ преобразования резюме :: Строка System :: String, то, возможно, это может помочь вам:

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

, а затем использовать ул везде, где вы хотите!

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* 
Смежные вопросы