본문 바로가기
C++ 200제/코딩 IT 정보

MFC CString to double 변환 사용법 (atof, wtof, tstof)

by vicddory 2017. 3. 26.

MFC CString to double 변환 사용법 (atof, wtof, tstof)


MFC에서 CString을 double로 변환하는 방법입니다.


아래엔 형 변환이 이뤄지는 3가지 예가 있는데, 공통적으로 CString은 LPCTSTR과 const char*로 먼저 변환이 됩니다. 변환된 char형의 자료를 함수들이 double로 변환을 하게 됩니다.


MFC, CString to double 변환 사용법 (atof, wtof, tstof)[MFC CString to double] 형변환 함수 atof, wtof, tstof



Knowing this, you can use atof():
 
CString thestring("13.37");
double d = atof(thestring).
...or for Unicode builds, _wtof():
 
CString thestring(L"13.37");
double d = _wtof(thestring).
...or to support both Unicode and non-Unicode builds...
 
CString thestring(_T("13.37"));
double d = _tstof(thestring).
(_tstof() is a macro that expands to either atof() or
_wtof() based on whether or not _UNICODE is defined)


MFC CString to double 변환 사용법 (atof, wtof, tstof)

댓글