Learning Objectives String Class.

Slides:



Advertisements
Similar presentations
Chapter 9 Strings. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 9-2 Learning Objectives An Array Type for Strings C-Strings Character.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
1 9/13/06CS150 Introduction to Computer Science 1 Type Casting.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 8 Strings and Vectors.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
Working with Strings Lecture 2 Hartmut Kaiser
J. P. Cohoon and J. W. Davidson © 1999 McGraw-Hill, Inc. Modifying objects Operators and Expressions.
Modifying objects Operators and Expressions JPC and JWD © 2002 McGraw-Hill, Inc.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
ITEC 320 C++ Examples.
9-1 Learning Objectives  An Array Type for Strings  C-Strings.
Chapter 3: Modifying objects Operators and Expressions JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strings and Vectors.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 8 Strings and Vectors.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
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
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Chapter 9 Strings. Learning Objectives An Array Type for Strings – C-Strings Character Manipulation Tools – Character I/O – get, put member functions.
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.
An Array Type For Strings. Two ways to represent strings – i.e. “Hello” cstring An array with base type char Older way of processing strings Null character.
More about strings in C++. String member functions The next three slides present information about functions that are members of the C++ string class.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 8 Strings and Vectors. Slide 8- 2 Overview 8.1 An Array Type for Strings 8.2 The Standard string Class 8.3 Vectors.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Copyright © 2002 Pearson Education, Inc. Slide 1.
Slide 1 Chapter 9 Strings. Slide 2 Learning Objectives  An Array Type for Strings  C-Strings  Character Manipulation Tools  Character I/O  get, put.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 7 Enumerated Types and Strings Types.
Lecture Overview Linked List quiz Finish last class' topic:
Strings: C-strings vs. Strings as Objects
Chapter 8 Strings and Vectors 1
Chapter 8 Strings and Vectors
CMSC 202 Lesson 2 C++ Primer.
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists Strings (part 2) Dr. Xiao Qin Auburn.
Chapter 9 Strings Copyright © 2016 Pearson, Inc. All rights reserved.
Working with Strings Lecture 2 Hartmut Kaiser
Characters, C-Strings, and More About the string Class
Basic Input and Output Operations
getline() function with companion ignore()
Standard Version of Starting Out with C++, 4th Edition
Object Oriented Programming COP3330 / CGS5409
Data Types Chapter 8.
C++ STRINGS string is part of the Standard C++ Library
Strings: C-strings vs. Strings as Objects
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
Working with Strings Lecture 2 Hartmut Kaiser
Operator Overloading; String and Array Objects
Strings A collection of characters taken as a set:
10.1 Character Testing.
Programming with Data Files
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Wednesday 09/23/13.
String What it is Why it’s useful
Chapter 9 Strings Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Engineering Problem Solving with C++, Etter
CS 144 Advanced C++ Programming February 7 Class Meeting
Standard Version of Starting Out with C++, 4th Edition
Using string type variables
Strings Skill Area 313 Part C
COMS 261 Computer Science I
Today’s Objectives 28-Jun-2006 Announcements
Programming Strings.
getline() function with companion ignore()
Chapter 12: More on C-Strings and the string Class
Presentation transcript:

Learning Objectives String Class

Topic 1: String Class Two string types: C-strings String class Array with base type char End of string marked with null, "\0" "Older" method inherited from C String class New method

Standard Class string Defined in library: #include <string> using namespace std; String variables and expressions Treated much like simple data types Can assign, compare, add: string s1, s2, s3; s1 = "Hello”; //Assignment s2 = “Mom! ” //Assignment s3 = s1 + “ ” + s2; //Concatenation

I/O with Class string Just like other types! string s1, s2; cin >> s1; cin >> s2; Results: User types in: May the hair on your toes grow long and curly! Extraction still ignores whitespace: s1 receives value "May" s2 receives value "the"

getline() with Class string For complete lines: string line; cout << "Enter a line of input: "; getline(cin, line); cout << line << "\n"; Dialogue produced: Enter a line of input: Do be do to you! Do be do to you!

Class string Processing Same operations available as c-strings: Over 100 members of standard string class Some member functions: .length() Returns length of string variable .at(i) Returns reference to char at position I .substr(P, L) Returns a substring at position P and having length L

C-string and string Object Conversions Automatic type conversions From c-string to string object: char s1[] = "My C-string"; string s2; s2 = s1; Perfectly legal and appropriate! s1 = s2; ILLEGAL! Cannot auto-convert to c-string Must use explicit conversion: strcpy(s1, s2.c_str());