Which string classes to use in C++?

后端 未结 7 2156
遇见更好的自我
遇见更好的自我 2021-02-02 14:30

we have a multi-threaded desktop application in C++ (MFC). Currently developers use either CString or std::string, probably depending on their mood. So we\'d like to choose a s

7条回答
  •  情话喂你
    2021-02-02 14:31

    Actually, the answer may be "It depends". But, if you are using MFC, IMHO, CString usage would be better. Also, you can use CString with STL containers also. But, it will lead to another question, should I use stl containers or MFC containers with CString? Usage of CString will provide agility to your application for example in unicode conversions.

    EDIT: Moreover, if you use WIN32 api calls, CString conversions will be easier.

    EDIT: CString has a GetBuffer() and regarding methods that allow you to modify buffer directly.

    EDIT: I have used CString in our SQLite wrapper, and formatting CString is easier.

        bool RS::getString(int idx, CString& a_value) {
    
    //bla bla
    
            if(getDB()->getEncoding() == IDatabase::UTF8){
                a_value.Format(_T("%s"), sqlite3_column_text(getCommand()->getStatement(), idx));
            }else{
                a_value.Format(_T("%s"), sqlite3_column_text16(getCommand()->getStatement(), idx));
            }
            return true;
    }
    

提交回复
热议问题