c++中 string类的数据成员有哪些?

2025-12-18 02:51:26
推荐回答(3个)
回答1:

append
Adds characters to the end of a string.
向字符串尾部追加串。
assign
Assigns new character values to the contents of a string.
为字符串赋新值。
at
Returns a reference to the element at a specified location in the string.
返回指定位置上的字符。
back

begin
Returns an iterator addressing the first element in the string.
返回第一个位置的iterator地址。
c_str
Converts the contents of a string as a C-style, null-terminated, string.
转化为C格式的以null结尾的字符串。
capacity
Returns the largest number of elements that could be stored in a string without increasing the memory allocation of the string.
返回当前字符串的容量。
cbegin
Returns a const iterator addressing the first element in the string.
返回第一个位置的i常量terator地址。
cend
Returns a const iterator that addresses the location succeeding the last element in a string.
返回最后一个位置的常量iterator地址。
clear
Erases all elements of a string.
清空整个字符串。
compare
Compares a string with a specified string to determine if the two strings are equal or if one is lexicographically less than the other.
和另一个字符串比较大小。
data
Converts the contents of a string into an array of characters.
将字符串内容转化为字符串数组
empty
Tests whether the string contains characters.
判断是否为空
end
Returns an iterator that addresses the location succeeding the last element in a string.
返回最后一个位置的iterator地址。
erase
Removes an element or a range of elements in a string from a specified position.
删除指定位置上的一个或多个字符。
find
Searches a string in a forward direction for the first occurrence of a substring that matches a specified sequence of characters.
查找指定的字符串。
insert
Inserts an element or a number of elements or a range of elements into the string at a specified position.
插入一个或多个字符。
length
Returns the current number of elements in a string.
返回长度。
replace
Replaces elements in a string at a specified position with specified characters or characters copied from other ranges or strings or C-strings.
子串替换。
resize
Specifies a new size for a string, appending or erasing elements as required.
改变大小。
substr
Copies a substring of at most some number of characters from a string beginning from a specified position.
返回指定位置上的子串。

回答2:

http://msdn.microsoft.com/zh-cn/library/xabz5s9c
直接看MSDN吧

回答3:

这个也不少,你可以下载个C++函数使用手册查询下,或者登陆MSDN查询!