Visual c++ 在MFC(VC+;+;)中将CString转换为枚举类型?
如何在MFC(VC++)中将CString转换为枚举类型 我有一个方法将输入参数作为Enum,但我正在将Cstring值传递给它,以便将其转换为EnumVisual c++ 在MFC(VC+;+;)中将CString转换为枚举类型?,visual-c++,mfc,Visual C++,Mfc,如何在MFC(VC++)中将CString转换为枚举类型 我有一个方法将输入参数作为Enum,但我正在将Cstring值传递给它,以便将其转换为Enum CString strFolderType = strFolderType.Right(strFolderType.GetLength()-(fPos+1)); m_strFolderType = strFolderType ; 我有一个方法,比如 ProtocolIdentifier(eFolderType iFolderType) wh
CString strFolderType = strFolderType.Right(strFolderType.GetLength()-(fPos+1));
m_strFolderType = strFolderType ;
我有一个方法,比如
ProtocolIdentifier(eFolderType iFolderType)
where enum eFolderType
{
eFTP = 1,
eCIFS,
eBOTH
};
现在当我这样打电话的时候:
ProtocolIdentifier(m_strFolderType);
它说无法将CString转换为eFolderType
如何解决此问题?为什么
m\u strFolderType
是字符串?它似乎应该是一个eFolderType
没有自动方式将CString
转换为enum
(实际上是一个整数)。值eFTP
、eCIFS
和ebot
不是字符串,编译器不会将它们视为字符串
将整数作为字符串传递是很难看的。您应该传递一个eFolderType
作为参数。如果必须传递字符串(可能来自返回字符串的某个序列化),则必须执行以下操作:
eFolderType result = /* whichever should be the default*/ ;
if (m_strFolderType == _T("eFTP")) {
result = eFTP;
} else if (m_strFolderType == _T("eCIFS")) {
result = eCIFS;
} else if (m_strFolderType == _T("eBOTH")) {
result = eBOTH;
} else {
// Invalid value was passed: either use the default value or
// treat this as an error, depending on your requirements.
}