26-1strings - #include #include #include...

Info icon This 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 );
Image of page 1

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

View Full Document Right 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"); //cout << "astring.append(\"Some stuff\a\"): " << astring << endl; //string& append( const string& str, size_type index, size_type len ); string str1 = "Eventually I stopped caring..."; string str2 = "but that was the '80s so nobody noticed.";
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern