Download presentation
Presentation is loading. Please wait.
Published byWilfred Thompson Modified over 9 years ago
1
CS 1400 30 Oct 2006 Section 10.8
2
The string abstract data type C++ allows a programmer to add new data or variable types. The details of how this new data type is manipulated are hidden from the user One such added abstract data type is the string. In other words, the string data type is not native to C++, but has been added as an additional data type. Many such abstract data types are available.
3
The string abstract data type Access:#include Declaration: string name, names[10]; string thisname = “Fred”; Assignment:name = “Jane”; name1 = name2; I/O:cout << name; cin >> thisname Comparison:if (name1 < name2) … if (name == “Fred”) …
4
Member functions The developer of a new abstract data type can make functions available to manipulate the new data type. These functions are only available to this data type – and are called “member functions” All member functions are invoked with the dot operator following the owner data. Example: ifstream fin; fin.open (“myfile”);
5
Some string member functions 1.. append (str)append str to the end of this string 2..clear ()clear this string 3..empty ()return true if this string is empty 4..length ()return the current length of this string 5..find (str, pos)find str in this string beginning at pos 6..erase (pos, length)erase length characters at pos 7..replace (pos, length, str)replace length characters at pos with str 8..substr (pos, length)return the substring of length characters beginning at pos 9..insert (pos, str)insert str at pos in this string
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.