- CString을 char* 로 변환하기

1. memcpy 사용하기

CString str = "test";
unsigned char st[30];
memcpy(st, (unsigned char*)(LPCTSTR)str,i);

2. strcpy 사용하기

CString strData = "test";
int length = strData.GetLength();
char* st = new char[length];
strcpy(st, strData.GetBuffer(0));

3. 형변환 사용하기

CString str;
str = "test";
char* st = LPSTR(LPCTSTR(str));

- char* 를 CString으로 변환하기

CString클래스의 Format함수를 사용

char st[] = "test";
CString str;
str.Format("%s", st);


[출처 : http://frog3147.tistory.com/entry/CString%EA%B3%BC-char%EA%B0%84%EC%9D%98-%EB%B3%80%ED%99%98]

파일 상태를 읽으려면

  • CFile 클래스를 사용하여 파일 정보를 읽고 설정합니다. CFile 정적 멤버 함수인 GetStatus를 사용하여 파일의 존재 여부를 확인할 수 있습니다. 지정된 파일이 존재하지 않으면 GetStatus가 0을 반환합니다.

따라서 GetStatus 결과를 사용하여 다음 예제와 같이 파일을 열 때 CFile::modeCreate 플래그의 사용 여부를 결정할 수 있습니다.

CFile theFile;
char* szFileName = "c:\\test\\myfile.dat";
BOOL bOpenOK;

CFileStatus status;
if( CFile::GetStatus( szFileName, status ) )
{
    // Open the file without the Create flag
    bOpenOK = theFile.Open( szFileName, 
                    CFile::modeWrite );
}
else
{
    // Open the file with the Create flag
    bOpenOK = theFile.Open( szFileName, 
                    CFile::modeCreate | CFile::modeWrite );
}

[출처 : http://msdn.microsoft.com/ko-kr/library/cc451414(VS.71).aspx]

+ Recent posts