티스토리 뷰

C C++/메모장

변수 타입 간 변환 방법 정리

개발하는꼬물이 2018. 7. 16. 16:27

CString -> Int

CString str = _T("122"); 
int nStr = _ttoi(str); 
 

Int →  CString 

int n = 2; Cstring strN; 
strN.Format(_T("%d"), n);

 

CString → Double

Cstring str = _T("2"); 
double fstr = _tstof(str); 

 

Double →  CString

double dNum = 2.2; CString strNum; 
strNum.Format(_T("%f"), dNum);

 

CString → ASCII

CString strMsg; 
const char* convertMsg; 
CT2A ascii( strMsg , CP_UTF8 ); 
convertMsg = ascii.m_psz;

 

 

CString -> char*

CString strFile = _T(".\\test.txt"); 
USES_CONVERSION; 
char* temp = T2A(strFile); FILE* fp; fopen_s(&fp, temp, "r");
댓글