C++ Lecture 4 - size_type find(const string&,...

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

View Full Document Right Arrow Icon
C++ Lecture 4 http://www.cs.mun.ca/~gstarkes/3710/c++/lecture4.html 1 of 2 4/13/2009 5:28 PM C++ Lecture 4 [Previous Lecture] [Lecture Index] [Next Lecture] Intro to Standard String Class // Defines class string { . .. }; #include <std/string.h> manages and manipulates strings of characters (good replacement for the likes of char buf[1024]; ) grows as needed has rich set of methods & overloaded operators ( i.e., strcpy() , strcmp() , etc. no longer needed) can still get at C-style char * string if necessary. #include <std/string.h> int main() { string s, t; t = "hi"; t.append(" there"); cin >> s; cout << t << ' ' << s << endl; return 0; } More on Standard String Class string::size_type - type used to index characters in a string string::npos - contsant size_type that represents no possition ( e.g. , failure to find something) or `go to the end' ( e.g., subtr() method) Commonly used string methods: const char *c_str() : return C-style string size_type length() bool empty() size_type find(char c, size_type n = 0);
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: size_type find(const string&amp;, size_type n = 0); string substr(size_type pos = 0, size_type n = npos) Commonly used overloaded operators: ==- contents of strings the same? (also != , &lt; , &lt;= , &gt;= , &gt; ) =- assign a char * , char , or string +=- append a char * , char , or string +- creates and returns a new string related functions: ostream&amp; &lt;&lt; string&amp; C++ Lecture 4 http://www.cs.mun.ca/~gstarkes/3710/c++/lecture4.html 2 of 2 4/13/2009 5:28 PM write a string istream&amp; &gt;&gt; string&amp; read a (space delimited) string getline(istream&amp;, string&amp;, char delim='\n') read a line (not including the \n ) [Previous Lecture] [Lecture Index] [Next Lecture] This document was created with Win2PDF available at http://www.win2pdf.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only. This page will not be added after purchasing Win2PDF....
View Full Document

Page1 / 3

C++ Lecture 4 - size_type find(const string&amp;amp;amp;,...

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