2010-11-29 4 views
0

MFC (VC++)에서 CString을 Enum 형식으로 변환하는 방법은 무엇입니까?MFC (VC++)에서 CString을 Enum 형식으로 변환 하시겠습니까?

입력 매개 변수를 가져 오는 한 가지 방법이 있지만 열거 형으로 변환 할 수있는 Cstring 값을 전달하고 있습니다.

CString strFolderType = strFolderType.Right(strFolderType.GetLength()-(fPos+1)); 
m_strFolderType = strFolderType ; 

내가

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 ? 

답변

1

같은 하나 개의 방법이 왜 m_strFolderType 문자열입니다 있나요? eFolderType이어야합니다.

CStringenum (실제로는 정수)으로 변환하는 자동 방법이 없습니다. 값 eFTP, eCIFSeBOTH은 문자열이 아니므로 컴파일러에서 해당 값을 처리하지 않습니다.

정수로 문자열을 전달하는 것은 추악합니다. 인수로 eFolderType을 전달해야합니다. 문자열을 전달해야한다면 (아마도 문자열을 반환 한 일부 직렬화에서 온 것입니다) 다음과 같이해야합니다 :

관련 문제