CS 1400 30 Oct 2006 Section 10.8. The string abstract data type C++ allows a programmer to add new data or variable types. The details of how this new.

Slides:



Advertisements
Similar presentations
Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
Advertisements

ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12: More on C-Strings and the string Class Starting Out with.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
Lesson 10 Characters, C-Strings, and the string Class CS1 Lesson John Cole1.
The Standard String Class Is actually a template: –typedef basic_string string This means you can have strings of things other than chars.
CS 1400 Chapter 10 Strings. Character testing library #include bool isalpha (char c); bool isalnum (char c); bool isdigit (char c); bool islower (char.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
CS 1400 Apr 18, 2007 Chapter 10 Strings. Character testing library #include bool isalpha (char c); bool isalnum (char c); bool isdigit (char c); bool.
CS 1400 Chapter 7 ARRAYS. Array variables Simple variables can hold single values int x;// x can hold one integer float y; // y can hold one float Array.
CS 1400 Chapter 7 ARRAYS. Array variables Simple variables can hold single values int x;// x can hold one integer float y; // y can hold one float Array.
Strings Representation and Manipulation. Objects Objects : Code entities uniting data and behavior – Built from primitive data types.
String Constructors string str; // creates an empty //string string str(“abc”); // creates a string // from a C-string string str(aString); // creates.
Data Type string #include // C++ String class string str1, str2; // Default constructor cin >> str1 >> str2; cout
One Dimensional Arrays (Part2) Sorting Algorithms Searching Algorithms Character Strings The string Class. 1.
Chapter 10 Applications of Arrays and Strings. Chapter Objectives Learn how to implement the sequential search algorithm Explore how to sort an array.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 8: The string Type.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
File I/O ifstreams and ofstreams Sections 11.1 &
Vectors and Grids Eric Roberts CS 106B April 8, 2009.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Characters, Strings, And The string Class Chapter 10.
String Class. C-style and C++ string Classes C-style strings, called C-strings, consist of characters stored in an array ( we’ll look at them later) C++
Sahar Mosleh California State University San MarcosPage 1 The C++ String Class The contents of this particular lecture prepared by the instructors at the.
1 Strings, Classes, and Working With Class Interfaces CMPSC 122 Penn State University Prepared by Doug Hogan.
1 Character Strings (Cstrings) Reference: CS215 textbook pages
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
CSC 270 – Survey of Programming Languages
String Class Mohamed Shehata 1020: Introduction to Programming.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
1 CS161 Introduction to Computer Science Topic #16.
CS 1430: Programming in C++ 1. Data Type string #include // C++ String class string str1, str2; // Default constructor cin >> str1 >> str2; cout
C++ STRINGS ● string is part of the Standard C++ Library ● new stuff: ● cin : standard input stream (normally the keyboard) of type istream. ● >> operator.
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
STL string class Programming Team 2/15/2006. string constructors string() = empty string string(int l, char ch) = string of length l, of repeated ch string(char*
What is a String? A string is actually a character array.
1 Strings in C++ The string Class Definition of Strings How to declare strings in C++: the string class Operations on strings –Concatenation, comparison.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Strings, and the string Class. C-Strings C-string: sequence of characters stored in adjacent memory locations and terminated by NULL character The C-string.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
Library Functions. CSCE 1062 Outline  cmath class library functions {section 3.2}  iomanip class library functions {section 8.5}  string class library.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Microsoft Visual Basic 2005: Reloaded Second Edition
C-Strings We have already seen that a C-string is a null-terminated array of characters.
CS Computer Science IA: Procedural Programming
Data Streams.
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
C++ STRINGS string is part of the Standard C++ Library
Chapter 8: The string Type
Strings A collection of characters taken as a set:
10.1 Character Testing.
Learning Objectives Classes Constructors Principles of OOP
String class and its objects
Wednesday 09/23/13.
Text Analyzer BIS1523 – Lecture 14.
Representation and Manipulation
File I/O.
Additional string operators
Data Structures: Abstract Data Types (ADTs)
character manipulation
Chapter 12: More on C-Strings and the string Class
Presentation transcript:

CS Oct 2006 Section 10.8

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.

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”) …

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”);

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