1

I searched for a while trying to find if there was a similar question, but couldn't.

How can I convert System::String^ (from VC++) to cv::String (from OpenCV)?

double x, y;
x = 10;
y = 10;
System::String ^ displayString = System::String::Concat("( ", x, " , ", y, " )");
char * test1 = displayString->ToCharArray;
cv::String test = cv::String(test1)

gives the error

Severity    Code    Description Project File    Line    Suppression State
Error   C3867   'System::String::ToCharArray': non-standard syntax; use '&' to create a pointer to member   RobocopComputerVision   RobocopComputerVision   .cpp    156 

What is the best way to convert System::String^ to cv::String?

Shivanand
  • 144
  • 1
  • 1
  • 13
  • 1
    https://stackoverflow.com/questions/1300718/c-net-convert-systemstring-to-stdstring#1300903 – zindarod Nov 14 '17 at 23:12
  • @zindarod That worked because cv::String had a constructor for std::String. Do you want to write it as an answer? – Shivanand Nov 14 '17 at 23:36

1 Answers1

0

Just try this,

#include <msclr\marshal_cppstd.h>
using namespace msclr::interop;
/* ... ... */
System::String ^ displayString = System::String::Concat("( ", x, " , ", y,")");
cv::String test = marshal_as<std::string>(displayString);
TheUnknown
  • 66
  • 1
  • 10