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

后端 未结 5 738
囚心锁ツ
囚心锁ツ 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:46

    First : define char *inputString; in your_file.h

    Second : define in yourFile.cpp : CString MyString;

    MyString = "Place here whatever you want";
    
    inputString = new char[MyString.GetLength()];
    inputString = MyString.GetBuffer(MyString.GetLength());
    

    The last two sentences convert a CString variable to a char*; but be carefull, with CString you can hold millons of charcteres but with char* no. You have to define the size of your char* varible.

提交回复
热议问题