26-1strings - #include <iostream> #include...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <string> #include <cstring> using namespace std; /* http://www.cppreference.com/cppstring/index.html append append characters and strings onto a string assign give a string values from strings of characters and other C++ strings at returns an element at a specific location begin returns an iterator to the beginning of the string ***NOT YET COVERED c_str returns a standard C character array version of the string capacity returns the number of elements that the string can hold clear removes all elements from the string compare compares two strings copy copies characters from a string into an array data returns a pointer to the first character of a string empty true if the string has no elements end returns an iterator just past the last element of a string ***NOT YET COVERED erase removes elements from a string find find characters in the string find_first_not_of find first absence of characters find_first_of find first occurrence of characters find_last_not_of find last absence of characters find_last_of find last occurrence of characters getline read data from an I/O stream into a string insert insert characters into a string length returns the length of the string max_size returns the maximum number of elements that the string can hold push_back add an element to the end of the string rbegin returns a reverse_iterator to the end of the string rend returns a reverse_iterator to the beginning of the string replace replace characters in the string reserve sets the minimum capacity of the string resize change the size of the string rfind find the last occurrence of a substring size returns the number of items in the string substr returns a certain substring swap swap the contents of this string with another */ int main (void) { /* append() * appends str on to the end of the current string, * appends a substring of str starting at index that is len characters long on to the end of the current string, * appends num characters of str on to the end of the current string, * appends num repititions of ch on to the end of the current string, * or appends the sequence denoted by start and end on to the end of the current string. *//* append overloads: string& append( const string& str ); string& append( const char* str ); string& append( const string& str, size_type index, size_type len ); string& append( const char* str, size_type num ); string& append( size_type num, char ch ); string& append( input_iterator start, input_iterator end );
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
*/ string astring = "Oh, this is so much fun, I can hardly stand it :-) "; // string is a class type cout << "Our string is: " << astring << endl; cout << "Our string is: " << sizeof(string) << " bytes\n"; string appendMe = "Something to append\n"; //string& append( const string& str ); astring.append(appendMe); cout << "astring.append(appendMe); Our string is: " << astring << endl; cout << "Our string is: " << sizeof(string) << " bytes\n"; //string& append( const char* str ); astring.append("Some stuff\a");
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

26-1strings - #include &lt;iostream&gt; #include...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online