hyeonk lab

블로그 이미지

hyeonk

hello world! hyeonk lab.

CString과 char*간의 변환

mfc & winAPI 2012. 12. 7. 15:52

- 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); //이렇게 하거나

str = st;                   //이렇게 해도 된다.

-> 그러나 데이터 타입 상 이렇게 하는게 더 정확히 변환하는것이다.

str = (LPCSTR)(LPSTR)st;

 

인용글 + 자체글 포함됨.

출처: http://frog3147.tistory.com/entry/CString과-char간의-변환

'mfc & winAPI' 카테고리의 다른 글

CString 형변환 Programming  (0) 2013.02.13
LPSTR LPCTSTR 위험 CString -> char 으로 변환  (0) 2013.02.13
MFC 에서 strcat 함수 말고 StringCchCopy 함수를 사용하자.  (0) 2012.12.07
MFC HotKey 등록  (0) 2012.11.05
중복실행 방지코드  (0) 2012.03.07
Posted by hyeonk
블로그 이미지

hello world! hyeonk lab.

by hyeonk

공지사항

    최근...

  • 포스트
  • 댓글
  • 트랙백
  • 더 보기

태그

글 보관함

«   2025/12   »
일 월 화 수 목 금 토
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

링크

카테고리

전체 (44)
ios (1)
mfc & winAPI (17)
c & c++ (4)
java (1)
eclipse (1)
visual_studio (2)
javascript (3)
asp (1)
oracle (3)
개발이야기 (5)
윈도우 일반 (2)
etc (2)
reference (2)
personal_reference (0)

카운터

Total
Today
Yesterday
방명록 : 관리자 : 글쓰기
hyeonk's Blog is powered by daumkakao
Skin info material T Mark3 by 뭐하라
favicon

hyeonk lab

hello world! hyeonk lab.

  • 태그
  • 링크 추가
  • 방명록

관리자 메뉴

  • 관리자 모드
  • 글쓰기
  • 전체 (44)
    • ios (1)
    • mfc & winAPI (17)
    • c & c++ (4)
    • java (1)
    • eclipse (1)
    • visual_studio (2)
    • javascript (3)
    • asp (1)
    • oracle (3)
    • 개발이야기 (5)
    • 윈도우 일반 (2)
    • etc (2)
    • reference (2)
    • personal_reference (0)

카테고리

PC화면 보기 티스토리 Daum

티스토리툴바