将string类转换成char *的常用方法为:
string str;
const char *str1;
str1=str.c_str();
这在读取图像文件名时很有用,因为如果用cvLoadImage()的话括号里面的参数只能为const char*型,而一般对文件名的读取都是用string类,这样比较灵活。
下文转载自:http://blog.sina.com.cn/s/blog_a50d2d7401019aeu.html
const char* && string && String^ 类型转换
const char* && string && String^ 类型转换
comment:
const char* ---> string
1:
string ---> const char*
1:
using namespace std;
string s = "kkkkk";
const char* cc = s.data();
const char* ---String^
using namespace System::Runtime::InteropServices;
1:
const char* cc = "dddddddddd";
System::String^ cmStr = gcnew System::String(cc);
2:
const char* iconData = "sjhfksssssl";
String^ temp = String(iconData).ToString();
String^ ---> const char*
1:
using namespace System::Runtime::InteropServices;
String^ ---> string
1:
using namespace System::Runtime::InteropServices;
string ---> String^
string sw = "shkhk";
const char* cw = sw.data();
String^ temp = String(cw).ToString();