Problem: How to convert CString into const char * in C++ MFC

后端 未结 5 675
囚心锁ツ
囚心锁ツ 2021-01-21 11:32

How do I convert CString into const char *? I have tried everything found on the internet but I still cant convert them.

Please help.

Thank you.

5条回答
  •  旧巷少年郎
    2021-01-21 11:48

    CString casts to const char * directly

    CString temp;
    temp = "Wow";
    const char * foo = (LPCSTR) temp;
    printf("%s", foo);
    

    will print 'foo'

    Newer version of MFC also support the GetString() method:

    CString temp;
    temp = "Wow";
    const char * foo = temp.GetString();
    printf("%s", foo);
    

提交回复
热议问题