TAILIEUCHUNG - Thinking in C plus plus (P20)

Tham khảo tài liệu 'thinking in c plus plus (p20)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | a or . The overloaded non member comparison operators for the string class are limited to the subset which has clear unambiguous application to single characters or groups of characters. The compare member function offers you a great deal more sophisticated and precise comparison than the non member operator set because it returns a lexical comparison value and provides for comparisons that consider subsets of the string data. It provides overloaded versions that allow you to compare two complete strings part of either string to a complete string and subsets of two strings. This example compares complete strings C01 Demonstrates compare swap include string include iostream using namespace std int main string first This string second That Which is lexically greater switch second case 0 The same cout first and second are lexically equal endl break case -1 Less than second Fall through this case. case 1 Greater than cout first is lexically greater than second endl The output from looks like this This is lexically greater than That To compare a subset of the characters in one or both strings you add arguments that define where to start the comparison and how many characters to consider. For example we can use the overloaded version of compare s1StartPos slNumberChars s2 s2StartPos s2NumberChars If we substitute the above version of compare in the previous program so that it only looks at the first two characters of each string the program becomes Chapter 14 Templates Container Classes 51 C01 Overloaded compare include string include iostream using namespace std int main string first This string second That Compare first two characters of each string switch 0 2 second 0 2 case 0 The same cout first and second are lexically equal endl break case -1 Less than second Fall through this case. case 1 Greater than cout first is lexically greater than second endl The output is This

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.