I read data from a file and I wanted to use on of its values in a function. This is a custom function, I am programming TOOLKIT for Creo Parametric.
Well, that function is expecting a 'xrstring' but I have a std::string.
How to I convert one into another?
I've tried writing xrstring test_var = xrstring(std_var);
And it doesn't work.
//definition of xrstring
typedef const char *xrstring;
#define xstringuninit ((xrstring) 2)
#define xstringnil ((const char *) 1)
#define xwstringnil ((const wchar_t *) 1)
#define xwstringuninit ((const wchar_t *) 2)
//definition of pfcCreateStringParamValue
pfcParamValue_ptr pfcCreateStringParamValue (xrstring Value);
error C2664: 'pfcParamValue_ptr pfcCreateStringParamValue(xrstring)': cannot convert argument 1 from 'std::string' to 'xrstring'
xrstring test_var(std_var.c_str());std::stringobject to a pointer tochar(const or not), and you have never been able to do that. You need to explicitly do it using thec_strfunction. This should be well known to all who studied a little.xrstring test_var = std_var.c_str();thetest_varis only valid for as long as the life span ofstd_var, and only as long asstd_varis not modified. Iftest_varneeds to live longer than that,std::strdupwill make a copy, but then you need tostd::freethat memory when done withtest_var.char *to a buffer of characters. Thestd::string::c_str()function provides such a pointer.