To access a library use a preprocessor directive to add its definitions to your

To access a library use a preprocessor directive to

This preview shows page 18 - 25 out of 30 pages.

To access a library use a preprocessor directive to add its definitions to your program file #include <string> The using using statement makes syntax less clumsy Without it std::string s = "Sharp"; std::string t = "Spiffy "; With it using namespace std; using namespace std; // std contains string string s = "Sharp"; string t = "Spiffy";
Image of page 18
Class string Class string Some string member functions size() determines number of characters in the string string strSaying = "Rambling with Gambling"; cout << strSaying.size() << endl; // 22 substr() determines a substring (Note first position has index 0) string strWord = strSaying.substr(9, 4); // with find() computes the position of a subsequence int j = strSaying.find("it"); // 10 int k = strSaying.find("its"); // ?
Image of page 19
Class string Class string Auxiliary functions and operators getline() extracts the next input line string Response; cout << "Enter text: "; getline(cin, Response, '\n'); cout << "Response is \"" << Response << "\"” << endl; Example run Enter text: Want what you do Response is "Want what you do"
Image of page 20
Class string Class string Auxiliary operators + string concatenation string strPart1 = "Me"; string strPart2 = " and "; string strPart3 = "You"; string strAll = strPart1 + strPart2 + strPart3; += compound concatenation assignment string strThePlace = "Brooklyn"; strThePlace += ", NY"; Program 3.4
Image of page 21
EzWindows EzWindows Library Objects Library Objects Definitions are the same form as other objects Example SimpleWindow W; Most non-fundamental classes have been created so that an object is automatically initialized to a sensible value SimpleWindow objects have member functions to process messages to manipulate the objects Most important member function is Open() which causes the object to be displayed on the screen Example W.Open();
Image of page 22
An An EzWindows EzWindows Program Program #include <iostream> using namespace std; #include "ezwin.h" int ApiMain() { SimpleWindow W("A Window", 12, 12); W.Open(); cout << "Enter a character to exit" << endl; char a; cin >> a; return 0; }
Image of page 23
RectangleShape RectangleShape Objects Objects EzWindows also provides RectangleShape RectangleShape for manipulating rectangles RectangleShape RectangleShape objects can specify the following attributes SimpleWindow object that contains the rectangle (mandatory) Offset from left edge of the SimpleWindow Offset from top edge of the SimpleWindow Offsets are measured in centimeters from rectangle center Width in centimeters Height in centimeters Color color is an EzWindows type
Image of page 24
Image of page 25

You've reached the end of your free preview.

Want to read all 30 pages?

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes