1. Trang chủ
  2. » Công Nghệ Thông Tin

ansi C reference phần 3 pot

191 215 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

21–12 Strings library DRAFT: 28 April 1995 21.1.1.6 basic_string capacity 1 The member function reserve() is a directive that informs a basic_string of a planned change in size, so that it can manage the storage allocation accordingly. Effects: After reserve(), capacity() is greater or equal to the argument of reserve if realloca- tion happens; and equal to the previous value of capacity() otherwise. Reallocation happens at this point if and only if the current capacity is less than the argument of reserve(). Complexity: It does not change the size of the sequence and takes at most linear time in the size of the sequence. Notes: Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence. It is guaranteed that no reallocation takes place during the insertions that happen after reserve() takes place till the time when the size of the string reaches the size specified by reserve(). bool empty() const; Returns: size() == 0. [lib.string.access] 21.1.1.7 basic_string element access charT operator[](size_type pos ) const; reference operator[](size_type pos ); Returns: If pos < size(), returns data()[ pos ]. Otherwise, if pos == size(), the const version returns traits::eos(). Otherwise, the behavior is undefined. Notes: The reference returned by the non-const version is invalid after any subsequent call to c_str(), data(), or any non-const member function for the object. const_reference at(size_type n ) const; reference at(size_type n ); Requires: pos < size() Throws: out_of_range if pos >= size(). Returns: operator[]( pos ). [lib.string.modifiers] 21.1.1.8 basic_string modifiers [lib.string::op+=] 21.1.1.8.1 basic_string::operator+= basic_string<charT,traits,Allocator>& operator+=(const basic_string<charT,traits,Allocator>& rhs ); Returns: append( rhs ). basic_string<charT,traits,Allocator>& operator+=(const charT* s ); Returns: *this += basic_string<charT,traits,Allocator>( s ). Notes: Uses traits::length(). basic_string<charT,traits,Allocator>& operator+=(charT c ); Returns: *this += basic_string<charT,traits,Allocator>( c ). 21.1.1.8.2 basic_string::append DRAFT: 28 April 1995 Strings library 21–13 [lib.string::append] 21.1.1.8.2 basic_string::append basic_string<charT,traits,Allocator>& append(const basic_string<charT,traits>& str, size_type pos = 0, size_type n = npos); Requires: pos <= size() Throws: out_of_range if pos > str .size(). Effects: Determines the effective length rlen of the string to append as the smaller of n and str .size() - pos . The function then throws length_error if size() >= npos - rlen . Otherwise, the function replaces the string controlled by *this with a string of length size() + rlen whose first size() elements are a copy of the original string controlled by *this and whose remaining elements are a copy of the initial elements of the string controlled by str beginning at posi- tion pos . Returns: *this. basic_string<charT,traits,Allocator>& append(const charT* s , size_type n ); Returns: append(basic_string<charT,traits,Allocator>( s , n )). basic_string<charT,traits,Allocator>& append(const charT* s ); Returns: append(basic_string<charT,traits,Allocator>( s )). Notes: Uses traits::length(). basic_string<charT,traits,Allocator>& append(size_type n , charT c = charT()); Returns: append(basic_string<charT,traits,Allocator>( c , n )). template<class InputIterator> basic_string& append(InputIterator first , InputIterator last ); Returns: append(basic_string<charT,traits,Allocator>( first , last )). [lib.string::assign] 21.1.1.8.3 basic_string::assign basic_string<charT,traits,Allocator>& assign(const basic_string<charT,traits>& str , size_type pos = 0, size_type n = npos); Requires: pos <= size() Throws: out_of_range if pos > str .size(). Effects: Determines the effective length rlen of the string to assign as the smaller of n and str .size() - pos . The function then replaces the string controlled by *this with a string of length rlen whose elements are a copy of the string controlled by str beginning at position pos . Returns: *this. basic_string<charT,traits,Allocator>& assign(const charT* s , size_type n ); 21–14 Strings library DRAFT: 28 April 1995 21.1.1.8.3 basic_string::assign Returns: assign(basic_string<charT,traits,Allocator>( s , n )). basic_string<charT,traits,Allocator>& assign(const charT* s ); Returns: assign(basic_string( s )). Notes: Uses traits::length(). basic_string<charT,traits,Allocator>& assign(size_type n , charT c = charT()); Returns: assign(basic_string<charT,traits,Allocator>( c , n )). template<class InputIterator> basic_string& assign(InputIterator first , InputIterator last ); Returns: assign(basic_string<charT,traits,Allocator>( first , last )). [lib.string::insert] 21.1.1.8.4 basic_string::insert basic_string<charT,traits,Allocator>& insert(size_type pos1 , const basic_string<charT,traits,Allocator>& str , size_type pos2 = 0, size_type n = npos); Requires pos1 <= size() Throws: out_of_range if pos1 > size() or pos2 > str .size(). Effects: Determines the effective length rlen of the string to insert as the smaller of n and str .size() - pos2 . Then throws length_error if size() >= npos - rlen . Otherwise, the function replaces the string controlled by *this with a string of length size() + rlen whose first pos1 elements are a copy of the initial elements of the original string controlled by *this, whose next rlen elements are a copy of the elements of the string controlled by str begin- ning at position pos2 , and whose remaining elements are a copy of the remaining elements of the origi- nal string controlled by *this. Returns: *this. basic_string<charT,traits,Allocator>& insert(size_type pos , const charT* s , size_type n ); Returns: insert( pos ,basic_string<charT,traits,Allocator>( s , n )). basic_string<charT,traits,Allocator>& insert(size_type pos , const charT* s ); Returns: insert( pos ,basic_string<charT,traits,Allocator>( s )). Notes: Uses traits::length(). basic_string<charT,traits,Allocator>& insert(size_type pos , size_type n , charT c = charT()); Returns: insert( pos ,basic_string<charT,traits,Allocator>( c , n )). iterator insert(iterator p , charT c = charT()); 21.1.1.8.4 basic_string::insert DRAFT: 28 April 1995 Strings library 21–15 Requires: p is a valid iterator on *this. Effects: inserts a copy of c before the character referred to by p . Returns: p . iterator insert(iterator p , size_type n , charT c = charT()); Requires: p is a valid iterator on *this. Effects: inserts n copies of c before the character referrred to by p . template<class InputIterator> void insert(iterator p , InputIterator first , InputIterator last ); Requires: p is a valid iterator on *this. [ first , last ) is a valid range. Effects: inserts copies of the characters in the range [ first , last ) before the character referrred to by p . [lib.string::remove] 21.1.1.8.5 basic_string::remove basic_string<charT,traits,Allocator>& remove(size_type pos = 0, size_type n = npos); Requires: pos <= size() Throws: out_of_range if pos > size(). Effects: Determines the effective length xlen of the string to be removed as the smaller of n and size() - pos . The function then replaces the string controlled by *this with a string of length size() - xlen whose first pos elements are a copy of the initial elements of the original string controlled by *this, and whose remaining elements are a copy of the elements of the original string controlled by *this beginning at position pos + xlen . Returns: *this. basic_string& remove(iterator p ); Requires: p is a valid iterator on *this. Effects: removes the character referred to by p and calls the character’s destructor. Returns: *this. basic_string& remove(iterator first , iterator last ); Requires: first and last are valid iterators on *this, defining a range [ first , last ). Effects: removes the characters in the range [ first , last ) and calls the character’s destructor. Complexity: the destructor is called a number of times exactly equal to the size of the range. Returns: *this. [lib.string::replace] 21.1.1.8.6 basic_string::replace basic_string<charT,traits,Allocator>& replace(size_type pos1 , size_type n1 , const basic_string<charT,traits,Allocator>& str , size_type pos2 = 0, size_type n2 = npos); Requires: pos1 <= size() && pos2 <= size(). Throws: out_of_range if pos1 > size() or pos2 > str .size(). 21–16 Strings library DRAFT: 28 April 1995 21.1.1.8.6 basic_string::replace Effects: Determines the effective length xlen of the string to be removed as the smaller of n1 and size() - & pos1 . It also determines the effective length rlen of the string to be inserted as the smaller of n2 and str .size() - pos2 . Throws length_error if size() - xlen >= npos - rlen . Otherwise, the function replaces the string controlled by *this with a string of length size() - xlen + rlen whose first pos1 elements are a copy of the initial elements of the original string con- trolled by *this, whose next rlen elements are a copy of the initial elements of the string controlled by str beginning at position pos2 , and whose remaining elements are a copy of the elements of the original string controlled by *this beginning at position pos1 + xlen . Returns: *this. basic_string<charT,traits,Allocator>& replace(size_type pos , size_type n1 , const charT* s , size_type n2 ); Returns: replace( pos , n1 ,basic_string<charT,traits,Allocator>( s , n2 )). basic_string<charT,traits,Allocator>& replace(size_type pos, size_type n1, const charT* s ); Returns: replace( pos , n1 ,basic_string<charT,traits,Allocator>( s )). Notes: Uses traits::length(). basic_string<charT,traits,Allocator>& replace(size_type pos , size_type n , charT c = charT()); Returns: replace( pos , n ,basic_string<charT,traits,Allocator>( c , n )). basic_string& replace(iterator i1 , iterator i2 , const basic_string& str ); Requires: The iterators i1 and i2 are valid iterators on *this, defining a range [ i1 , i2 ). Effects: Replaces the string controlled by *this with a string of length size() - ( i2 - i1 ) + str .size() whose first begin() - i1 elements are a copy of the initial elements of the original string controlled by *this, whose next str .size() elements are a copy of the string controlled by str , and whose remaining elements are a copy of the elements of the original string controlled by *this beginning at position i2 . Returns: *this. Notes: After the call, the length of the string will be changed by: str .size() - ( i2 - i1 ). basic_string& replace(iterator i1 , iterator i2 , const charT* s , size_type n ); Returns: replace( i1 , i2 ,basic_string( s , n )). Notes: Length change: n - ( i2 - i1 ). basic_string& replace(iterator i1 , iterator i2 , const charT* s ); Returns: replace( i1 , i2 ,basic_string( s )). Notes: Length change: traits::length( s ) - ( i2 - i1 ). Uses traits::length(). basic_string& replace(iterator i1 , iterator i2 , size_type n , charT c = charT()); 21.1.1.8.6 basic_string::replace DRAFT: 28 April 1995 Strings library 21–17 Returns: replace( i1 , i2 ,basic_string( n , c )). Notes: Length change: n - ( i2 - i1 ). template<class InputIterator> basic_string& replace(iterator i1 , iterator i2 , InputIterator j1 , InputIterator j2 ); Returns: replace( i1 , i2 ,basic_string( j1 , j2 )). Notes: Length change: j2 - j1 - ( i2 - i1 ). [lib.string::copy] 21.1.1.8.7 basic_string::copy size_type copy(charT* s , size_type n , size_type pos = 0); Requires: pos <= size() Throws: out_of_range if pos > size(). Effects: Determines the effective length rlen of the string to copy as the smaller of n and size() - pos . s shall designate an array of at least rlen elements. The function then replaces the string designated by s with a string of length rlen whose elements are a copy of the string controlled by *this beginning at position pos . Notes: The function does not append a null object to the string. Returns: rlen . [lib.string::swap] 21.1.1.8.8 basic_string::swap void swap(basic_string<charT,traits,Allocator>& s ); Effects: Swaps the contents of the two strings. Postcondition: *this contains the characters that were in s , s contains the characters that were in *this. Complexity: Constant time. [lib.string.ops] 21.1.1.9 basic_string string operations const charT* c_str() const; Returns: A pointer to the initial element of an array of length size() + 1 whose first size() ele- ments equal the corresponding elements of the string controlled by *this and whose last element is a null character specified by traits::eos(). Requires: The program shall not alter any of the values stored in the array. Nor shall the program treat the returned value as a valid pointer value after any subsequent call to a non-const member function of the class basic_string that designates the same object as this. Notes: Uses traits::eos(). const charT* data() const; Returns: c_str() if size() is nonzero, otherwise a null pointer. Requires: The program shall not alter any of the values stored in the character array. Nor shall the pro- gram treat the returned value as a valid pointer value after any subsequent call to a non- const member function of basic_string that designates the same object as this. 21–18 Strings library DRAFT: 28 April 1995 21.1.1.9.1 basic_string::find [lib.string::find] 21.1.1.9.1 basic_string::find size_type find(const basic_string<charT,traits,Allocator>& str , size_type pos = 0) const; Effects: Determines the lowest position xpos , if possible, such that both of the following conditions obtain: — pos <= xpos and xpos + str .size() <= size(); — at( xpos + I ) == str .at( I ) for all elements I of the string controlled by str . Returns: xpos if the function can determine such a value for xpos . Otherwise, returns npos. Notes: Uses traits::eq(). size_type find(const charT* s , size_type pos , size_type n ) const; Returns: find(basic_string<charT,traits,Allocator>( s , n ) pos ). size_type find(const charT* s , size_type pos = 0) const; Returns: find(basic_string<charT,traits,Allocator>( s ), pos ). Notes: Uses traits::length(). size_type find(charT c , size_type pos = 0) const; Returns: find(basic_string<charT,traits,Allocator>( c ), pos ). [lib.string::rfind] 21.1.1.9.2 basic_string::rfind size_type rfind(const basic_string<charT,traits,Allocator>& str , size_type pos = npos) const; Effects: Determines the highest position xpos , if possible, such that both of the following conditions obtain: — xpos <= pos and xpos + str .size() <= size(); — at( xpos + I ) == str .at( I ) for all elements I of the string controlled by str . Returns: xpos if the function can determine such a value for xpos . Otherwise, returns npos. Notes: Uses traits::eq(). size_type rfind(const charT* s , size_type pos , size_type n ) const; Returns: rfind(basic_string<charT,traits,Allocator>( s , n ), pos ). size_type rfind(const charT* s , size_type pos = npos) const; Returns: rfind(basic_string<charT,traits,Allocator>( s ), pos ). Notes: Uses traits::length(). size_type rfind(charT c , size_type pos = npos) const; Returns: rfind(basic_string<charT,traits,Allocator>( c , n ), pos ). 21.1.1.9.3 DRAFT: 28 April 1995 Strings library 21–19 basic_string::find_first_of [lib.string::find.first.of] 21.1.1.9.3 basic_string::find_first_of size_type find_first_of(const basic_string<charT,traits,Allocator>& str , size_type pos = 0) const; Effects: Determines the lowest position xpos , if possible, such that both of the following conditions obtain: — pos <= xpos and xpos < size(); — at( xpos ) == str .at( I ) for some element I of the string controlled by str . Returns: xpos if the function can determine such a value for xpos . Otherwise, returns npos. Notes: Uses traits::eq(). size_type find_first_of(const charT* s , size_type pos , size_type n ) const; Returns: find_first_of(basic_string<charT,traits,Allocator>( s , n ), pos ). size_type find_first_of(const charT* s , size_type pos = 0) const; Returns: find_first_of(basic_string<charT,traits,Allocator>( s ), pos ). Notes: Uses traits::length(). size_type find_first_of(charT c , size_type pos = 0) const; Returns: find_first_of(basic_string<charT,traits,Allocator>( c ), pos ). [lib.string::find.last.of] 21.1.1.9.4 basic_string::find_last_of size_type find_last_of(const basic_string<charT,traits,Allocator>& str , size_type pos = npos) const; Effects: Determines the highest position xpos , if possible, such that both of the following conditions obtain: — xpos <= pos and pos < size(); — at( xpos ) == str .at( I ) for some element I of the string controlled by str . Returns: xpos if the function can determine such a value for xpos . Otherwise, returns npos. Notes: Uses traits::eq(). size_type find_last_of(const charT* s , size_type pos , size_type n ) const; Returns: find_last_of(basic_string<charT,traits,Allocator>( s , n ), pos ). size_type find_last_of(const charT* s , size_type pos = npos) const; Returns: find_last_of(basic_string<charT,traits,Allocator>( s ), pos ). Notes: Uses traits::length(). size_type find_last_of(charT c , size_type pos = npos) const; 21–20 Strings library DRAFT: 28 April 1995 21.1.1.9.4 basic_string::find_last_of Returns: find_last_of(basic_string<charT,traits,Allocator>( c ), pos ). [lib.string::find.first.not.of] 21.1.1.9.5 basic_string::find_first_not_of size_type find_first_not_of(const basic_string<charT,traits,Allocator>& str , size_type pos = 0) const; Effects: Determines the lowest position xpos , if possible, such that both of the following conditions obtain: — pos <= xpos and xpos < size(); — at( xpos ) == str .at( I ) for no element I of the string controlled by str . Returns: xpos if the function can determine such a value for xpos . Otherwise, returns npos. Notes: Uses traits::eq(). size_type find_first_not_of(const charT* s , size_type pos , size_type n ) const; Returns: find_first_not_of(basic_string<charT,traits,Allocator>( s , n ), pos ). size_type find_first_not_of(const charT* s , size_type pos = 0) const; Returns: find_first_not_of(basic_string<charT,traits,Allocator>( s ), pos ). Notes: Uses traits::length(). size_type find_first_not_of(charT c , size_type pos = 0) const; Returns: find_first_not_of(basic_string<charT,traits,Allocator>( c ), pos ). [lib.string::find.last.not.of] 21.1.1.9.6 basic_string::find_last_not_of size_type find_last_not_of(const basic_string<charT,traits,Allocator>& str , size_type pos = npos) const; Effects: Determines the highest position xpos , if possible, such that both of the following conditions obtain: — xpos <= pos and pos < size(); — at( xpos ) == str .at( I )) for no element I of the string controlled by str . Returns: xpos if the function can determine such a value for xpos . Otherwise, returns npos. Notes: Uses traits::eq(). size_type find_last_not_of(const charT* s , size_type pos , size_type n ) const; Returns: find_last_not_of(basic_string<charT,traits,Allocator>( s , n ), pos ). size_type find_last_not_of(const charT* s , size_type pos = npos) const; Returns: find_last_not_of(basic_string<charT,traits,Allocator>( s ), pos ). 21.1.1.9.6 DRAFT: 28 April 1995 Strings library 21–21 basic_string::find_last_not_of Notes: Uses traits::length(). size_type find_last_not_of(charT c , size_type pos = npos) const; Returns: find_last_not_of(basic_string<charT,traits,Allocator>( c ), pos ). [lib.string::substr] 21.1.1.9.7 basic_string::substr basic_string<charT,traits,Allocator> substr(size_type pos = 0, size_type n = npos) const; Requires: pos <= size() Throws: out_of_range if pos > size(). Effects: Determines the effective length rlen of the string to copy as the smaller of n and size() - pos . Returns: basic_string<charT,traits,Allocator>(data()+ pos , rlen ). [lib.string::compare] 21.1.1.9.8 basic_string::compare int compare(const basic_string<charT,traits,Allocator>& str , size_type pos = 0, size_type n = npos) Requires: pos <= size() Throws: out_of_range if pos > size(). Effects: Determines the effective length rlen of the strings to compare as the smallest of n , size() - pos , and str .size(). The function then compares the two strings by calling traits::compare(data()+ pos , str .data(), rlen ). Returns: the nonzero result if the result of the comparison is nonzero. Otherwise, returns a value as indi- cated in Table 44: Table 44—compare() results _ _____________________________________________ Condition Return Value _ _____________________________________________ _ _____________________________________________ size()- pos < str .size() < 0 size()- pos == str .size() 0 size()- pos > str.size() > 0 _ _____________________________________________             Notes: Uses traits::compare(). int compare(const charT* s , size_type pos , size_type n ) const; Returns: compare(basic_string<charT,traits,Allocator>( s , n ), pos ). Notes: Uses traits::compare(). int compare(const charT* s , size_type pos = 0) const; Returns: compare(basic_string<charT,traits,Allocator>( s ), pos ). Notes: Uses traits::length() and traits::compare(). [...]... isalnum (charT template bool isgraph (charT template charT toupper(charT template charT tolower(charT c, c, c, c, c, c, c, c, c, c, c, c, c, 22.1 Locales const const const const const const const const const const const const const locale& locale& locale& locale& locale& locale& locale& locale& locale& locale& locale& locale& locale& loc) loc) loc) loc) loc) loc)... of these functions isF returns the result of the expression: c, c, c, c, c, c, c, c, c, c, c, const const const const const const const const const const const locale& locale& locale& locale& locale& locale& locale& locale& locale& locale& locale& loc) loc) loc) loc) loc) loc) loc) loc) loc) loc) loc) const; const; const; const; const; const; const; const; const; const; const; 22– 10 Localization library... loc) loc) loc) loc) loc) loc) loc) const; const; const; const; const; const; const; const; const; const; const; const; const; // subclauses 22.2.1 and 22.2.1 .3, ctype: class ctype_base; template class ctype; // specialization class ctype; template class ctype_byname; class ctype_byname; // specialization class codecvt_base; template . mbsrtowcs wcrtomb wcsncat wcstok wmemset fwide putwc wcscat wcsncmp wcstol wprintf fwprintf putwchar wcschr wcsncpy wcstoul wscanf fwscanf swprintf wcscmp wcspbrk wcsxfrm getwc swscanf wcscoll wcsrchr. assign(wchar_t& c1 , const wchar_t& c2 ); Effects: c1 = c2 . static bool eq(const wchar_t& c1 , const wchar_t& c2 ); Returns: c1 == c2 . static bool ne(const wchar_t& c1 , const wchar_t& c2 ); Returns:. c2 . static bool ne(const char& c1 , const char& c2 ); Returns: c1 != c2 . static bool lt(const char& c1 , const char& c2 ); Returns: c1 < c2 . static char eos(); Returns: 0. basic_istream<char>&

Ngày đăng: 09/08/2014, 12:22

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN