Link to home
Start Free TrialLog in
Avatar of stephencushen
stephencushen

asked on

cstring = string

Simple question!

i have a string myString = "01010110";
i need to convert the string into a cstring myCSting

i thought you could say myCString = mystring.
But this throws up a conversion error.

what the best way to get around this error?

Avatar of jimbucci
jimbucci

operator= should work with a char*
I performed the following test with success:

char sz[] = "hello";
CString s;
s = sz;

How is myString defined?

Jim
Avatar of stephencushen

ASKER

the code is as follows

void CMFCCalculatorDlg::OnDecRadio()
{
string binaryValue = decObj.getBinaryValue();
CString m_edit = binaryValue;

UpdateData(FALSE);
}


that was the code that produces the error.
the code is as follows

void CMFCCalculatorDlg::OnDecRadio()
{
string binaryValue = decObj.getBinaryValue();
CString m_edit = binaryValue;

UpdateData(FALSE);
}


that was the code that produces the error.
I assume string is:

typedef unsigned char* string;

try:
CString m_edit(binaryValue);

Jim
no im not using a typedef.
im using the string data type. i include "#include <string>" at the top of the prog.
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or

CString m_edit(binaryValue.c_str());

You need to use the c_str() member function to pass the const char* pointer to CString object.
oh, string is from the STL.
Then Axter's solution is the right answer.

I wasn't sure where string came from - sorry.

JB