阿摩線上測驗 登入

申論題資訊

試卷:110年 - 110-2 國立清華大學期末考試題_電機工程學系:計算機程式設計#112945
科目:程式設計
年份:110年
排序:0

題組內容

1. (20%) Answer the following questions briefly.

申論題內容

(d) Given a C++ string object, s, sometimes we perform s.c_str(). What is the return type of this member function? (5%)

詳解 (共 1 筆)

詳解 提供者:hchungw

In C++, the c_str() member function of the std::string class returns a pointer to a null-terminated character array with data equivalent to that held by the string. Specifically, it returns a const char* type. This pointer points to the internal array managed by the string object and can be used to interface with C-style strings or functions that require a C-style string (null-terminated character array). The data it points to includes all the characters in the string followed by a null character (\0) at the end to mark the end of the array.在C++中,

C++中,std::string類的c_str()成員函數返回一個指向以空字元終止的字元數組的指針,該數組的數據與字串持有的數據相當。具體來說,它返回一個const char*類型的指針。這個指針指向由字串對象管理的內部數組,可用於與C風格的字串或需要C風格字串(以空字元終止的字元數組)的函數進行介面。它指向的數據包括字串中的所有字元,以及數組末尾的一個空字元(\0),以標記數組的結束。