how to Convert CString to Enum type in MFC(VC++) ?
I have one method which take input parameter as Enum but i am passing Cstring value to it how i can convert it to enum.
CString strFolderType = strFolderType.Right(strFolderType.GetLength()-(fPos+1));
m_strFolderType = strFolderType ;
I have one method as
ProtocolIdentifier(eFolderType iFolderType)
where enum eFolderType
{
eFTP = 1,
eCIFS,
eBOTH
};
now when i am calling like this :
ProtocolIdentifier(m_strFolderType);
It says cannot convert CString to eFolderType …
How to resolve this ?
Why is
m_strFolderTypea string? It seems like it should be aneFolderType.There is no automatic way to convert a
CStringto anenum(which is really an integer). The valueseFTP,eCIFS, andeBOTHare not strings and the compiler will not treat them as such.Passing an integer as a string is ugly. You should pass an
eFolderTypeas the argument. If you must pass a string (perhaps it came from some serialization that returned a string), you will have to do something like this: