两个重载函数中的std :: string了我的注意:串与char *字符串的版本::追加(),字符串替换::()和字符串::比较()
string& append(const string& str, size_t pos, size_t n);
string& append(const char* s, size_t n);
我很好奇的是为什么串::附加的字符*版本()不提供额外的参数size_t pos
,如下之一:
string& append(const char* s, size_t pos, size_t n);
对于其它两个功能,情况也是相同的:
int compare(size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2) const;
int compare(size_t pos1, size_t n1, const char* s, size_t n2) const;
string& replace(size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2);
string& replace(size_t pos1, size_t n1, const char* s, size_t n2);
这些函数的char *版本缺少参数size_t pos2
,这不像它们的字符串&副本那样灵活。我的问题如下:
- 为什么std :: string设计它的接口是这样的?
- 为什么char *版本函数还有
size_t pos
呢? - 背后有什么考虑?
谢谢您的阅读!
+1;) – chill
此外,'str.append(PTR,POS,LEN);'只有一个字符不是'str.append短(PTR + POS ,len);'(这取决于你的空白习惯)。 – zneak